commit 4bdaa5b8b1471449edc731f8a1333eaf98959cdb
parent 018fbd477d2c150e65d08aef49053bd625e7feb6
Author: ukai <ukai>
Date: Wed, 30 Jan 2002 15:08:48 +0000
[w3m-dev 02933] segmentation fault when w3m -dump https:
* file.c (readHeader): use inputAnswer()
* file.c (getAuthCookie): remove term_cbreak()
* file.c (checkOverWrite): use inputAnswer()
* file.c (inputAnswer): added
* istream.c (ssl_get_certificate): use inputAnswer()
* main.c (qquitfm): change prompt
* proto.h (inputAnswer): added
From: Hironori Sakamoto <hsaka@mth.biglobe.ne.jp>
Diffstat:
5 files changed, 52 insertions(+), 34 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -1,3 +1,14 @@
+2002-01-31 Hironori Sakamoto <hsaka@mth.biglobe.ne.jp>
+
+ * [w3m-dev 02933] segmentation fault when w3m -dump https:
+ * file.c (readHeader): use inputAnswer()
+ * file.c (getAuthCookie): remove term_cbreak()
+ * file.c (checkOverWrite): use inputAnswer()
+ * file.c (inputAnswer): added
+ * istream.c (ssl_get_certificate): use inputAnswer()
+ * main.c (qquitfm): change prompt
+ * proto.h (inputAnswer): added
+
2002-01-30 Hironori Sakamoto <hsaka@mth.biglobe.ne.jp>
* [w3m-dev 02931] use POST in multipart.cgi
diff --git a/file.c b/file.c
@@ -731,16 +731,14 @@ readHeader(URLFile *uf, Buffer *newBuf, int thru, ParsedURL *pu)
? "y" : NULL;
if (fmInitialized && (err & COO_OVERRIDE_OK) &&
accept_bad_cookie == ACCEPT_BAD_COOKIE_ASK) {
- Str msg =
- Sprintf
- ("Accept bad cookie from %s for %s? (y or n) ",
- pu->host,
- domain
- && domain->ptr ? domain->ptr : "<localdomain>");
- if (msg->length > COLS - 4)
- Strshrink(msg, msg->length - (COLS - 4));
- term_raw();
- ans = inputChar(msg->ptr);
+ Str msg = Sprintf("Accept bad cookie from %s for %s?",
+ pu->host,
+ ((domain && domain->ptr)
+ ? domain->ptr : "<localdomain>"));
+ if (msg->length > COLS - 10)
+ Strshrink(msg, msg->length - (COLS - 10));
+ Strcat_charp(msg, " (y/n)");
+ ans = inputAnswer(msg->ptr);
}
if (ans == NULL || tolower(*ans) != 'y' ||
(err =
@@ -1222,7 +1220,6 @@ getAuthCookie(struct http_auth *hauth, char *auth_header,
IN_PASSWORD)) == NULL)
return NULL;
pwd = Str_conv_to_system(Strnew_charp(pp));
- term_cbreak();
}
else {
int proxy = !strncasecmp("Proxy-Authorization:", auth_header,
@@ -6393,22 +6390,34 @@ int
checkOverWrite(char *path)
{
struct stat st;
- char buf[2];
- char *ans = NULL;
+ char *ans;
if (stat(path, &st) < 0)
return 0;
+ ans = inputAnswer("File exists. Overwrite? (y/n)");
+ if (ans && tolower(*ans) == 'y')
+ return 0;
+ else
+ return -1;
+}
+
+char *
+inputAnswer(char *prompt)
+{
+ char *ans;
+ char buf[2];
+
if (fmInitialized) {
- ans = inputChar("File exists. Overwrite? (y or n)");
+ term_raw();
+ ans = inputChar(prompt);
}
else {
- printf("File exists. Overwrite? (y or n)");
- ans = fgets(buf, 2, stdin);
+ printf(prompt);
+ fflush(stdout);
+ fgets(buf, 2, stdin);
+ ans = allocStr(buf, 1);
}
- if (ans != NULL && (*ans == '\0' || tolower(*ans) == 'y'))
- return 0;
- else
- return -1;
+ return ans;
}
static void
diff --git a/istream.c b/istream.c
@@ -476,11 +476,10 @@ ssl_get_certificate(InputStream stream, char *hostname)
&& strcasecmp(accept_this_site->ptr, hostname) == 0)
ans = "y";
else {
- emsg = Strnew_charp("No SSL peer certificate: accept (y/n)?");
- term_raw();
- ans = inputChar(emsg->ptr);
+ emsg = Strnew_charp("No SSL peer certificate: accept? (y/n)");
+ ans = inputAnswer(emsg->ptr);
}
- if (tolower(*ans) == 'y')
+ if (ans && tolower(*ans) == 'y')
amsg = Strnew_charp
("Accept SSL session without any peer certificate");
else {
@@ -510,11 +509,10 @@ ssl_get_certificate(InputStream stream, char *hostname)
&& strcasecmp(accept_this_site->ptr, hostname) == 0)
ans = "y";
else {
- emsg = Sprintf("%s: accept (y/n)?", em);
- term_raw();
- ans = inputChar(emsg->ptr);
+ emsg = Sprintf("%s: accept? (y/n)", em);
+ ans = inputAnswer(emsg->ptr);
}
- if (tolower(*ans) == 'y') {
+ if (ans && tolower(*ans) == 'y') {
amsg = Sprintf("Accept unsecure SSL session: "
"unverified: %s", em);
}
@@ -537,11 +535,10 @@ ssl_get_certificate(InputStream stream, char *hostname)
Str ep = Strdup(emsg);
if (ep->length > COLS - 16)
Strshrink(ep, ep->length - (COLS - 16));
- term_raw();
- Strcat_charp(ep, ": accept(y/n)?");
- ans = inputChar(ep->ptr);
+ Strcat_charp(ep, ": accept? (y/n)");
+ ans = inputAnswer(ep->ptr);
}
- if (tolower(*ans) == 'y') {
+ if (ans && tolower(*ans) == 'y') {
amsg = Strnew_charp("Accept unsecure SSL session:");
Strcat(amsg, emsg);
}
diff --git a/main.c b/main.c
@@ -2095,8 +2095,8 @@ qquitfm(void)
char *ans;
if (!confirm_on_quit)
quitfm();
- ans = inputChar("Do you want to exit w3m? (y or n)");
- if (ans != NULL && tolower(*ans) == 'y')
+ ans = inputChar("Do you want to exit w3m? (y/n)");
+ if (ans && tolower(*ans) == 'y')
quitfm();
displayBuffer(Currentbuf, B_NORMAL);
}
diff --git a/proto.h b/proto.h
@@ -184,6 +184,7 @@ extern void doFileSave(URLFile uf, char *defstr);
extern int checkCopyFile(char *path1, char *path2);
extern int checkSaveFile(InputStream stream, char *path);
extern int checkOverWrite(char *path);
+extern char *inputAnswer(char *prompt);
extern int matchattr(char *p, char *attr, int len, Str *value);
extern char *checkHeader(Buffer *buf, char *field);
extern Buffer *newBuffer(int width);