Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d1c5752

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 14570c2 commit d1c5752

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

contrib/pg_xlogdump/pg_xlogdump.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ fuzzy_open_file(const char *directory, const char *fname)
171171
fd = open(fname, O_RDONLY | PG_BINARY, 0);
172172
if (fd < 0 && errno != ENOENT)
173173
return -1;
174-
else if (fd > 0)
174+
else if (fd >= 0)
175175
return fd;
176176

177177
/* XLOGDIR / fname */
@@ -180,7 +180,7 @@ fuzzy_open_file(const char *directory, const char *fname)
180180
fd = open(fpath, O_RDONLY | PG_BINARY, 0);
181181
if (fd < 0 && errno != ENOENT)
182182
return -1;
183-
else if (fd > 0)
183+
else if (fd >= 0)
184184
return fd;
185185

186186
datadir = getenv("PGDATA");
@@ -192,7 +192,7 @@ fuzzy_open_file(const char *directory, const char *fname)
192192
fd = open(fpath, O_RDONLY | PG_BINARY, 0);
193193
if (fd < 0 && errno != ENOENT)
194194
return -1;
195-
else if (fd > 0)
195+
else if (fd >= 0)
196196
return fd;
197197
}
198198
}
@@ -204,7 +204,7 @@ fuzzy_open_file(const char *directory, const char *fname)
204204
fd = open(fpath, O_RDONLY | PG_BINARY, 0);
205205
if (fd < 0 && errno != ENOENT)
206206
return -1;
207-
else if (fd > 0)
207+
else if (fd >= 0)
208208
return fd;
209209

210210
/* directory / XLOGDIR / fname */
@@ -213,7 +213,7 @@ fuzzy_open_file(const char *directory, const char *fname)
213213
fd = open(fpath, O_RDONLY | PG_BINARY, 0);
214214
if (fd < 0 && errno != ENOENT)
215215
return -1;
216-
else if (fd > 0)
216+
else if (fd >= 0)
217217
return fd;
218218
}
219219
return -1;

0 commit comments

Comments
 (0)