]> git.apps.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
src/fill2: fix segfault during fopen error cleanup
authorAnthony Iliopoulos <ailiop@suse.com>
Thu, 12 Jun 2025 19:05:13 +0000 (21:05 +0200)
committerZorro Lang <zlang@kernel.org>
Fri, 20 Jun 2025 16:46:47 +0000 (00:46 +0800)
When fill2 fails to open the output file (e.g. due to ENOSPC), it jumps
into the cleanup code where it attempts to call fclose, and this causes
a segfault within the glibc fclose code as it attempts to deref a null
pointer.

Fix it by conditionally calling fclose on the file pointer only when
non-null.

This is consistently reproducible with xfs/041.

Signed-off-by: Anthony Iliopoulos <ailiop@suse.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Zorro Lang <zlang@redhat.com>
Signed-off-by: Zorro Lang <zlang@kernel.org>
src/fill2.c

index 4cc1c3d79a98b9286ba1dd1d8750349e3d88548d..37ed00b1d9b165b63fe19938d67c34e1de52670a 100644 (file)
@@ -307,7 +307,7 @@ main(int argc, char **argv)
  cleanup:
 
     /* close file and flush buffers - check if this fails */
-    if (fclose(f) != 0) {
+    if (f && fclose(f) != 0) {
        fprintf(stderr, "fill2: fclose() on \"%s\" failed: %s\n",
                dfile, strerror(errno));
        status = 1;