Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
tool_formparse: handle file2memory()'s return value correctly
Now, file2memory() returns PARAM_FILE_ERROR when ferror(stdin) would be
true; since `PARAM_READ_ERROR != PARAM_OK', the `if(ferror(stdin))' code
became unreachable.

Also, it's no longer necessary to free and set `data' to NULL in this
case.
  • Loading branch information
emanuele6 committed Apr 14, 2022
1 parent f8d8332 commit 8d6eb8f
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/tool_formparse.c
Expand Up @@ -125,21 +125,20 @@ static struct tool_mime *tool_mime_new_filedata(struct tool_mime *parent,
else { /* Not suitable for direct use, buffer stdin data. */
size_t stdinsize = 0;

if(file2memory(&data, &stdinsize, stdin) != PARAM_OK) {
/* Out of memory. */
switch(file2memory(&data, &stdinsize, stdin)) {
case PARAM_NO_MEM:
return m;
}

if(ferror(stdin)) {
case PARAM_READ_ERROR:
result = CURLE_READ_ERROR;
Curl_safefree(data);
data = NULL;
}
else if(!stdinsize) {
/* Zero-length data has been freed. Re-create it. */
data = strdup("");
if(!data)
return m;
break;
default:
if(!stdinsize) {
/* Zero-length data has been freed. Re-create it. */
data = strdup("");
if(!data)
return m;
}
break;
}
size = curlx_uztoso(stdinsize);
origin = 0;
Expand Down

0 comments on commit 8d6eb8f

Please sign in to comment.