diff options
| author | Andres Freund | 2022-02-25 18:40:32 +0000 |
|---|---|---|
| committer | Andres Freund | 2022-02-25 18:40:32 +0000 |
| commit | 51c34165614bde5d44a356ba5f1f4f79d8893103 (patch) | |
| tree | 25e1d08a828a54159a990a2c0fbbcbaab1888ece /src | |
| parent | 3faa21bb761f52974cfc59dd9d3993f89d81f44e (diff) | |
pg_waldump: Fix error message for WAL files smaller than XLOG_BLCKSZ.
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 <horikyota.ntt@gmail.com>
Discussion: https://postgr.es/m/20220214.181847.775024684568733277.horikyota.ntt@gmail.com
Backpatch: 11-, the bug was introducedin fc49e24fa
Diffstat (limited to 'src')
| -rw-r--r-- | src/bin/pg_waldump/pg_waldump.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/bin/pg_waldump/pg_waldump.c b/src/bin/pg_waldump/pg_waldump.c index 639bfcd7f7d..cd202a50ced 100644 --- a/src/bin/pg_waldump/pg_waldump.c +++ b/src/bin/pg_waldump/pg_waldump.c @@ -210,8 +210,10 @@ search_directory(const char *directory, const char *fname) if (fd >= 0) { PGAlignedXLogBlock buf; + int r; - if (read(fd, buf.data, XLOG_BLCKSZ) == XLOG_BLCKSZ) + r = read(fd, buf.data, XLOG_BLCKSZ); + if (r == XLOG_BLCKSZ) { XLogLongPageHeader longhdr = (XLogLongPageHeader) buf.data; @@ -223,14 +225,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("not enough data in file \"%s\"", fname); - } + fatal_error("not enough data in file \"%s\"", fname); + close(fd); return true; } |
