config: parse_string() fix the dynamic buffer allocation failure code (coverity)

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
Jaroslav Kysela 2019-05-24 10:44:49 +02:00
parent 4aa960c48b
commit 990b1a53ed

View file

@ -4747,8 +4747,11 @@ static int parse_string(const char **ptr, char **val)
return -EINVAL;
case '\\':
c = parse_char(ptr);
if (c < 0)
if (c < 0) {
if (alloc > bufsize)
free(buf);
return c;
}
break;
default:
(*ptr)++;
@ -4768,12 +4771,17 @@ static int parse_string(const char **ptr, char **val)
alloc *= 2;
if (old_alloc == bufsize) {
buf = malloc(alloc);
memcpy(buf, _buf, old_alloc);
} else {
buf = realloc(buf, alloc);
}
if (!buf)
return -ENOMEM;
memcpy(buf, _buf, old_alloc);
} else {
char *buf2 = realloc(buf, alloc);
if (!buf2) {
free(buf);
return -ENOMEM;
}
buf = buf2;
}
}
buf[idx++] = c;
}