pg_waldump: Fix error message for WAL files smaller than XLOG_BLCKSZ.
authorAndres Freund <[email protected]>
Fri, 25 Feb 2022 18:30:05 +0000 (10:30 -0800)
committerAndres Freund <[email protected]>
Fri, 25 Feb 2022 18:34:38 +0000 (10:34 -0800)
When opening a WAL file smaller than XLOG_BLCKSZ (e.g. 0 bytes long) while
determining the wal_segment_size, pg_waldump checked errno, despite errno not
being set by the short read. Resulting in a bogus error message.

Author: Kyotaro Horiguchi <[email protected]>
Discussion: https://postgr.es/m/20220214.181847.775024684568733277[email protected]
Backpatch: 11-, the bug was introducedin fc49e24fa

src/bin/pg_waldump/pg_waldump.c

index 0fee1ebdee155a23671961328c02ad3230a29160..b1e5f4610455c70182d6adedb772213389e21e76 100644 (file)
@@ -207,15 +207,12 @@ search_directory(const char *directory, const char *fname)
                                     WalSegSz),
                            fname, WalSegSz);
        }
+       else if (r < 0)
+           fatal_error("could not read file \"%s\": %s",
+                       fname, strerror(errno));
        else
-       {
-           if (errno != 0)
-               fatal_error("could not read file \"%s\": %s",
-                           fname, strerror(errno));
-           else
-               fatal_error("could not read file \"%s\": read %d of %zu",
-                           fname, r, (Size) XLOG_BLCKSZ);
-       }
+           fatal_error("could not read file \"%s\": read %d of %zu",
+                       fname, r, (Size) XLOG_BLCKSZ);
        close(fd);
        return true;
    }