io: Fix use-after-free in ftw [BZ #26779]

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
This commit is contained in:
Martin Sebor 2022-01-25 17:39:02 -07:00
parent 7845064d2d
commit ee52ab25ba

View File

@ -323,8 +323,9 @@ open_dir_stream (int *dfdp, struct ftw_data *data, struct dir_data *dirp)
buf[actsize++] = '\0'; buf[actsize++] = '\0';
/* Shrink the buffer to what we actually need. */ /* Shrink the buffer to what we actually need. */
data->dirstreams[data->actdir]->content = realloc (buf, actsize); void *content = realloc (buf, actsize);
if (data->dirstreams[data->actdir]->content == NULL) data->dirstreams[data->actdir]->content = content;
if (content == NULL)
{ {
int save_err = errno; int save_err = errno;
free (buf); free (buf);