Skip to content

Commit 835a487

Browse files
committed
Fix off-by-one in pg_xlogdump's fuzzy_open_file().
In the unlikely case of stdin (fd 0) being closed, the off-by-one would lead to pg_xlogdump failing to open files. Spotted by Coverity. Backpatch to 9.3 where pg_xlogdump was introduced.
1 parent 2d8411a commit 835a487

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

contrib/pg_xlogdump/pg_xlogdump.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ fuzzy_open_file(const char *directory, const char *fname)
152152
fd = open(fname, O_RDONLY | PG_BINARY, 0);
153153
if (fd < 0 && errno != ENOENT)
154154
return -1;
155-
else if (fd > 0)
155+
else if (fd >= 0)
156156
return fd;
157157

158158
/* XLOGDIR / fname */
@@ -161,7 +161,7 @@ fuzzy_open_file(const char *directory, const char *fname)
161161
fd = open(fpath, O_RDONLY | PG_BINARY, 0);
162162
if (fd < 0 && errno != ENOENT)
163163
return -1;
164-
else if (fd > 0)
164+
else if (fd >= 0)
165165
return fd;
166166

167167
datadir = getenv("PGDATA");
@@ -173,7 +173,7 @@ fuzzy_open_file(const char *directory, const char *fname)
173173
fd = open(fpath, O_RDONLY | PG_BINARY, 0);
174174
if (fd < 0 && errno != ENOENT)
175175
return -1;
176-
else if (fd > 0)
176+
else if (fd >= 0)
177177
return fd;
178178
}
179179
}
@@ -185,7 +185,7 @@ fuzzy_open_file(const char *directory, const char *fname)
185185
fd = open(fpath, O_RDONLY | PG_BINARY, 0);
186186
if (fd < 0 && errno != ENOENT)
187187
return -1;
188-
else if (fd > 0)
188+
else if (fd >= 0)
189189
return fd;
190190

191191
/* directory / XLOGDIR / fname */
@@ -194,7 +194,7 @@ fuzzy_open_file(const char *directory, const char *fname)
194194
fd = open(fpath, O_RDONLY | PG_BINARY, 0);
195195
if (fd < 0 && errno != ENOENT)
196196
return -1;
197-
else if (fd > 0)
197+
else if (fd >= 0)
198198
return fd;
199199
}
200200
return -1;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy