curl -w: handle a blank input file correctly

Previously it would end up with an uninitialized memory buffer that
would lead to a crash or junk getting output.

Added test 1271 to verify.

Reported-by: Brian Carpenter
Closes #4786
This commit is contained in:
Daniel Stenberg 2020-01-04 11:41:35 +01:00
parent 1b71bc532b
commit 4c34af4c99
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
3 changed files with 51 additions and 3 deletions

View file

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@ -65,7 +65,7 @@ ParameterError file2string(char **bufp, FILE *file)
size_t alloc_needed;
char buffer[256];
size_t stringlen = 0;
string = malloc(alloc);
string = calloc(1, alloc);
if(!string)
return PARAM_NO_MEM;