1feee8
commit deea6ab1bcb2696be514e579f3263c234ecc1683
1feee8
Author: Martin Sebor <msebor@redhat.com>
1feee8
Date:   Tue Jan 25 17:39:02 2022 -0700
1feee8
1feee8
    io: Fix use-after-free in ftw [BZ #26779]
1feee8
    
1feee8
    Reviewed-by: Carlos O'Donell <carlos@redhat.com>
1feee8
    (cherry picked from commit ee52ab25ba875f458981fce22c54e3c04c7a17d3)
1feee8
1feee8
diff --git a/io/ftw.c b/io/ftw.c
1feee8
index cf08d9f101657df0..91a4e8e6de151ca1 100644
1feee8
--- a/io/ftw.c
1feee8
+++ b/io/ftw.c
1feee8
@@ -324,8 +324,9 @@ open_dir_stream (int *dfdp, struct ftw_data *data, struct dir_data *dirp)
1feee8
 	  buf[actsize++] = '\0';
1feee8
 
1feee8
 	  /* Shrink the buffer to what we actually need.  */
1feee8
-	  data->dirstreams[data->actdir]->content = realloc (buf, actsize);
1feee8
-	  if (data->dirstreams[data->actdir]->content == NULL)
1feee8
+	  void *content = realloc (buf, actsize);
1feee8
+	  data->dirstreams[data->actdir]->content = content;
1feee8
+	  if (content == NULL)
1feee8
 	    {
1feee8
 	      int save_err = errno;
1feee8
 	      free (buf);