scalloc parse_config input to make sure it terminates with '\0'

Otherwise strchr() can crash for files that don't end with '\n' because
it won't find a null char to terminate at.

Fixes #2934
This commit is contained in:
Orestis Floros
2017-09-12 12:29:01 +03:00
parent fd7319683d
commit 7b0f4abf4f
2 changed files with 42 additions and 1 deletions

View File

@ -1025,7 +1025,7 @@ bool parse_file(const char *f, bool use_nagbar) {
/* Then, allocate a new buffer and copy the file over to the new one,
* but replace occurrences of our variables */
char *walk = buf, *destwalk;
char *new = smalloc(stbuf.st_size + extra_bytes + 1);
char *new = scalloc(stbuf.st_size + extra_bytes + 1, 1);
destwalk = new;
while (walk < (buf + stbuf.st_size)) {
/* Find the next variable */