From 254291cc036befcbda5ec9e93086ccc7031be5eb Mon Sep 17 00:00:00 2001 From: hniksic Date: Sat, 4 Oct 2003 15:26:58 -0700 Subject: [PATCH] [svn] Fix crash when post-file is missing. --- src/ChangeLog | 5 +++++ src/http.c | 2 +- src/utils.c | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ChangeLog b/src/ChangeLog index a60938bf..ddb20397 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2003-10-05 Hrvoje Niksic + + * utils.c (file_size): Return -1 if fopen() returns NULL. Prior + to this patch, wget --post-file=nosuchfile dumped core. + 2003-10-04 Gisle Vanem * mswindows.c (run_with_timeout): Use WaitForSingleObject to wait diff --git a/src/http.c b/src/http.c index 6bb53f2d..92043a57 100644 --- a/src/http.c +++ b/src/http.c @@ -1015,7 +1015,7 @@ Accept: %s\r\n\ #endif write_error = iwrite (sock, opt.post_data, post_data_size); } - else if (opt.post_file_name) + else if (opt.post_file_name && post_data_size != 0) { #ifdef HAVE_SSL if (conn->scheme == SCHEME_HTTPS) diff --git a/src/utils.c b/src/utils.c index fb180e8d..99b317f7 100644 --- a/src/utils.c +++ b/src/utils.c @@ -574,6 +574,8 @@ file_size (const char *filename) that way we can also verify whether the file is readable. Inspired by the POST patch by Arnaud Wylie. */ FILE *fp = fopen (filename, "rb"); + if (!fp) + return -1; fseek (fp, 0, SEEK_END); size = ftell (fp); fclose (fp);