aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTatsuya Kinoshita <tats@debian.org>2018-03-04 14:54:59 +0000
committerGitHub <noreply@github.com>2018-03-04 14:54:59 +0000
commit4f2be7d71edba728917523ad1c5f9f5b90529106 (patch)
treeb0201f1c383c856f6ac538b6e4d384e172fbcb92
parentUpdate ChangeLog (diff)
parentAdd error handling code for fopen (diff)
downloadw3m-4f2be7d71edba728917523ad1c5f9f5b90529106.tar.gz
w3m-4f2be7d71edba728917523ad1c5f9f5b90529106.zip
Merge pull request #96 from ZhouyangJia/master
Fix crashes when some external APIs fail
-rw-r--r--file.c8
-rw-r--r--local.c5
-rw-r--r--url.c4
3 files changed, 14 insertions, 3 deletions
diff --git a/file.c b/file.c
index 9b0e947..0333e9a 100644
--- a/file.c
+++ b/file.c
@@ -611,8 +611,10 @@ readHeader(URLFile *uf, Buffer *newBuf, int thru, ParsedURL *pu)
if(w3m_reqlog){
FILE *ff;
ff = fopen(w3m_reqlog, "a");
- Strfputs(tmp, ff);
- fclose(ff);
+ if(ff){
+ Strfputs(tmp, ff);
+ fclose(ff);
+ }
}
if (src)
Strfputs(tmp, src);
@@ -7580,6 +7582,8 @@ loadImageBuffer(URLFile *uf, Buffer *newBuf)
tmp = Sprintf("<img src=\"%s\"><br><br>", html_quote(image.url));
tmpf = tmpfname(TMPF_SRC, ".html");
src = fopen(tmpf->ptr, "w");
+ if (src == NULL)
+ return NULL;
newBuf->mailcap_source = tmpf->ptr;
init_stream(&f, SCM_LOCAL, newStrStream(tmp));
diff --git a/local.c b/local.c
index 46ac579..56d589d 100644
--- a/local.c
+++ b/local.c
@@ -426,7 +426,10 @@ localcgi_post(char *uri, char *qstr, FormList *request, char *referer)
}
#ifdef HAVE_CHDIR /* ifndef __EMX__ ? */
- chdir(cgi_dir);
+ if (chdir(cgi_dir) == -1) {
+ fprintf(stderr, "failed to chdir to %s: %s\n", cgi_dir, strerror(errno));
+ exit(1);
+ }
#endif
execl(file, cgi_basename, NULL);
fprintf(stderr, "execl(\"%s\", \"%s\", NULL): %s\n",
diff --git a/url.c b/url.c
index d759383..348f501 100644
--- a/url.c
+++ b/url.c
@@ -1752,6 +1752,8 @@ openURL(char *url, ParsedURL *pu, ParsedURL *current,
write(sock, tmp->ptr, tmp->length);
if(w3m_reqlog){
FILE *ff = fopen(w3m_reqlog, "a");
+ if (ff == NULL)
+ return uf;
if (sslh)
fputs("HTTPS: request via SSL\n", ff);
else
@@ -1774,6 +1776,8 @@ openURL(char *url, ParsedURL *pu, ParsedURL *current,
write(sock, tmp->ptr, tmp->length);
if(w3m_reqlog){
FILE *ff = fopen(w3m_reqlog, "a");
+ if (ff == NULL)
+ return uf;
fwrite(tmp->ptr, sizeof(char), tmp->length, ff);
fclose(ff);
}