diff --git a/src/tool_getparam.c b/src/tool_getparam.c index fb27fffd1f..2e8d6d7b75 100644 --- a/src/tool_getparam.c +++ b/src/tool_getparam.c @@ -609,10 +609,10 @@ static ParameterError data_urlencode(struct GlobalConfig *global, } else { file = fopen(p, "rb"); - if(!file) - warnf(global, - "Couldn't read data from file \"%s\", this makes " - "an empty POST.", nextarg); + if(!file) { + errorf(global, "Failed to open %s", p); + return PARAM_READ_ERROR; + } } err = file2memory(&postdata, &size, file); @@ -1761,9 +1761,11 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */ } else { file = fopen(nextarg, "rb"); - if(!file) - warnf(global, "Couldn't read data from file \"%s\", this makes " - "an empty POST.", nextarg); + if(!file) { + errorf(global, "Failed to open %s", nextarg); + err = PARAM_READ_ERROR; + break; + } } if((subletter == 'b') || /* --data-binary */ @@ -2195,8 +2197,11 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */ size_t len; bool use_stdin = !strcmp(&nextarg[1], "-"); FILE *file = use_stdin?stdin:fopen(&nextarg[1], FOPEN_READTEXT); - if(!file) - warnf(global, "Failed to open %s", &nextarg[1]); + if(!file) { + errorf(global, "Failed to open %s", &nextarg[1]); + err = PARAM_READ_ERROR; + break; + } else { err = file2memory(&string, &len, file); if(!err && string) { @@ -2544,7 +2549,12 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */ } else { fname = nextarg; - file = fopen(nextarg, FOPEN_READTEXT); + file = fopen(fname, FOPEN_READTEXT); + if(!file) { + errorf(global, "Failed to open %s", fname); + err = PARAM_READ_ERROR; + break; + } } Curl_safefree(config->writeout); err = file2string(&config->writeout, file); diff --git a/src/var.c b/src/var.c index a332fab19f..f8f42f6665 100644 --- a/src/var.c +++ b/src/var.c @@ -431,12 +431,14 @@ ParameterError setvariable(struct GlobalConfig *global, file = stdin; else { file = fopen(line, "rb"); + if(!file) { + errorf(global, "Failed to open %s", line); + return PARAM_READ_ERROR; + } } - if(file) { - err = file2memory(&content, &clen, file); - /* in case of out of memory, this should fail the entire operation */ - contalloc = TRUE; - } + err = file2memory(&content, &clen, file); + /* in case of out of memory, this should fail the entire operation */ + contalloc = TRUE; if(!use_stdin) fclose(file); if(err) diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc index a0015b3b20..cb01122a3a 100644 --- a/tests/data/Makefile.inc +++ b/tests/data/Makefile.inc @@ -51,7 +51,7 @@ test226 test227 test228 test229 test230 test231 test232 test233 test234 \ test235 test236 test237 test238 test239 test240 test241 test242 test243 \ test244 test245 test246 test247 test248 test249 test250 test251 test252 \ test253 test254 test255 test256 test257 test258 test259 test260 test261 \ -test262 test263 test264 test265 test266 test267 test268 test269 test270 \ +test262 test263 test264 test265 test266 test267 test269 test270 \ test271 test272 test273 test274 test275 test276 test277 test278 test279 \ test280 test281 test282 test283 test284 test285 test286 test287 test288 \ test289 test290 test291 test292 test293 test294 test295 test296 test297 \ diff --git a/tests/data/test268 b/tests/data/test268 deleted file mode 100644 index 851af4133d..0000000000 --- a/tests/data/test268 +++ /dev/null @@ -1,55 +0,0 @@ - - - -HTTP -HTTP POST - - -# -# Server-side - - -HTTP/1.0 200 OK -Server: test-server/fake -Content-Type: text/html -Content-Length: 0 - -this is data even though Content-Length is set to zero - - -HTTP/1.0 200 OK -Server: test-server/fake -Content-Type: text/html -Content-Length: 0 - - - - -# -# Client-side - - -http - - -HTTP POST a non-existing file - - - -d @nonesuchfile http://%HOSTIP:%HTTPPORT/%TESTNUMBER - - - -# -# Verify data after the test has been "shot" - - -POST /%TESTNUMBER HTTP/1.1 -Host: %HOSTIP:%HTTPPORT -User-Agent: curl/%VERSION -Accept: */* -Content-Length: 0 -Content-Type: application/x-www-form-urlencoded - - - -