tool: change some fopen failures from warnings to errors

- Error on missing input file for --data, --data-binary,
  --data-urlencode, --header, --variable, --write-out.

Prior to this change if a user of the curl tool specified an input file
for one of the above options and that file could not be opened then it
would be treated as zero length data instead of an error. For example, a
POST using `--data @filenametypo` would cause a zero length POST which
is probably not what the user intended.

Closes https://github.com/curl/curl/pull/11677
This commit is contained in:
Jay Satiro 2023-08-20 03:08:15 -04:00
parent 2fe26a7c6a
commit aacbeae7bb
4 changed files with 28 additions and 71 deletions

View file

@ -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)