Merge pull request #2480 from LinkiTools/pmatos-clanganal-9

Avoid memcpy from null pointer in do_inotify_add
This commit is contained in:
Paulo Matos 2019-02-17 15:04:06 +01:00 committed by Matthew Flatt
parent d033dd1ed2
commit 41b282d3ae

View File

@ -450,11 +450,17 @@ static int do_inotify_add(rktio_t *rktio, const char *filename)
int new_size = (s->size ? (2 * s->size) : 32);
rin_wd_t *new_wds;
int i;
new_wds = (rin_wd_t *)malloc(sizeof(rin_wd_t) * new_size);
memcpy(new_wds, s->wds, s->size * sizeof(rin_wd_t));
if (s->wds) free(s->wds);
if (s->wds) {
memcpy(new_wds, s->wds, s->size * sizeof(rin_wd_t));
free(s->wds);
}
s->wds = new_wds;
s->size = new_size;
for (i = s->count; i < s->size; i++)
{
s->wds[i].wd = -1;