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

Commit b5bcef6

Browse files
committed
Fix some miscellaneous places that were using raw open() or
fopen(), instead of going through fd.c ... naughty naughty.
1 parent 71d5d95 commit b5bcef6

File tree

4 files changed

+56
-31
lines changed

4 files changed

+56
-31
lines changed

src/backend/libpq/be-fsstubs.c

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/libpq/be-fsstubs.c,v 1.29 1999/05/03 19:09:39 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/libpq/be-fsstubs.c,v 1.30 1999/05/09 00:54:30 tgl Exp $
1111
*
1212
* NOTES
1313
* This should be moved to a more appropriate place. It is here
@@ -99,7 +99,7 @@ lo_close(int fd)
9999
{
100100
MemoryContext currentContext;
101101

102-
if (fd >= MAX_LOBJ_FDS)
102+
if (fd < 0 || fd >= MAX_LOBJ_FDS)
103103
{
104104
elog(ERROR, "lo_close: large obj descriptor (%d) out of range", fd);
105105
return -2;
@@ -131,14 +131,34 @@ lo_close(int fd)
131131
int
132132
lo_read(int fd, char *buf, int len)
133133
{
134-
Assert(cookies[fd] != NULL);
134+
if (fd < 0 || fd >= MAX_LOBJ_FDS)
135+
{
136+
elog(ERROR, "lo_read: large obj descriptor (%d) out of range", fd);
137+
return -2;
138+
}
139+
if (cookies[fd] == NULL)
140+
{
141+
elog(ERROR, "lo_read: invalid large obj descriptor (%d)", fd);
142+
return -3;
143+
}
144+
135145
return inv_read(cookies[fd], buf, len);
136146
}
137147

138148
int
139149
lo_write(int fd, char *buf, int len)
140150
{
141-
Assert(cookies[fd] != NULL);
151+
if (fd < 0 || fd >= MAX_LOBJ_FDS)
152+
{
153+
elog(ERROR, "lo_write: large obj descriptor (%d) out of range", fd);
154+
return -2;
155+
}
156+
if (cookies[fd] == NULL)
157+
{
158+
elog(ERROR, "lo_write: invalid large obj descriptor (%d)", fd);
159+
return -3;
160+
}
161+
142162
return inv_write(cookies[fd], buf, len);
143163
}
144164

@@ -149,11 +169,16 @@ lo_lseek(int fd, int offset, int whence)
149169
MemoryContext currentContext;
150170
int ret;
151171

152-
if (fd >= MAX_LOBJ_FDS)
172+
if (fd < 0 || fd >= MAX_LOBJ_FDS)
153173
{
154-
elog(ERROR, "lo_seek: large obj descriptor (%d) out of range", fd);
174+
elog(ERROR, "lo_lseek: large obj descriptor (%d) out of range", fd);
155175
return -2;
156176
}
177+
if (cookies[fd] == NULL)
178+
{
179+
elog(ERROR, "lo_lseek: invalid large obj descriptor (%d)", fd);
180+
return -3;
181+
}
157182

158183
currentContext = MemoryContextSwitchTo((MemoryContext) fscxt);
159184

@@ -197,7 +222,7 @@ lo_creat(int mode)
197222
int
198223
lo_tell(int fd)
199224
{
200-
if (fd >= MAX_LOBJ_FDS)
225+
if (fd < 0 || fd >= MAX_LOBJ_FDS)
201226
{
202227
elog(ERROR, "lo_tell: large object descriptor (%d) out of range", fd);
203228
return -2;
@@ -255,7 +280,7 @@ lowrite(int fd, struct varlena * wbuf)
255280
Oid
256281
lo_import(text *filename)
257282
{
258-
int fd;
283+
File fd;
259284
int nbytes,
260285
tmp;
261286

@@ -269,13 +294,13 @@ lo_import(text *filename)
269294
*/
270295
StrNCpy(fnamebuf, VARDATA(filename), VARSIZE(filename) - VARHDRSZ + 1);
271296
#ifndef __CYGWIN32__
272-
fd = open(fnamebuf, O_RDONLY, 0666);
297+
fd = PathNameOpenFile(fnamebuf, O_RDONLY, 0666);
273298
#else
274-
fd = open(fnamebuf, O_RDONLY | O_BINARY, 0666);
299+
fd = PathNameOpenFile(fnamebuf, O_RDONLY | O_BINARY, 0666);
275300
#endif
276301
if (fd < 0)
277302
{ /* error */
278-
elog(ERROR, "be_lo_import: can't open unix file\"%s\"\n",
303+
elog(ERROR, "be_lo_import: can't open unix file \"%s\"\n",
279304
fnamebuf);
280305
}
281306

@@ -298,7 +323,7 @@ lo_import(text *filename)
298323
/*
299324
* read in from the Unix file and write to the inversion file
300325
*/
301-
while ((nbytes = read(fd, buf, BUFSIZE)) > 0)
326+
while ((nbytes = FileRead(fd, buf, BUFSIZE)) > 0)
302327
{
303328
tmp = inv_write(lobj, buf, nbytes);
304329
if (tmp < nbytes)
@@ -308,7 +333,7 @@ lo_import(text *filename)
308333
}
309334
}
310335

311-
close(fd);
336+
FileClose(fd);
312337
inv_close(lobj);
313338

314339
return lobjOid;
@@ -321,7 +346,7 @@ lo_import(text *filename)
321346
int4
322347
lo_export(Oid lobjId, text *filename)
323348
{
324-
int fd;
349+
File fd;
325350
int nbytes,
326351
tmp;
327352

@@ -331,7 +356,7 @@ lo_export(Oid lobjId, text *filename)
331356
mode_t oumask;
332357

333358
/*
334-
* create an inversion "object"
359+
* open the inversion "object"
335360
*/
336361
lobj = inv_open(lobjId, INV_READ);
337362
if (lobj == NULL)
@@ -343,17 +368,17 @@ lo_export(Oid lobjId, text *filename)
343368
/*
344369
* open the file to be written to
345370
*/
346-
oumask = umask((mode_t) 0);
347371
StrNCpy(fnamebuf, VARDATA(filename), VARSIZE(filename) - VARHDRSZ + 1);
372+
oumask = umask((mode_t) 0);
348373
#ifndef __CYGWIN32__
349-
fd = open(fnamebuf, O_CREAT | O_WRONLY | O_TRUNC, 0666);
374+
fd = PathNameOpenFile(fnamebuf, O_CREAT | O_WRONLY | O_TRUNC, 0666);
350375
#else
351-
fd = open(fnamebuf, O_CREAT | O_WRONLY | O_TRUNC | O_BINARY, 0666);
376+
fd = PathNameOpenFile(fnamebuf, O_CREAT | O_WRONLY | O_TRUNC | O_BINARY, 0666);
352377
#endif
353378
umask(oumask);
354379
if (fd < 0)
355380
{ /* error */
356-
elog(ERROR, "lo_export: can't open unix file\"%s\"",
381+
elog(ERROR, "lo_export: can't open unix file \"%s\"",
357382
fnamebuf);
358383
}
359384

@@ -362,7 +387,7 @@ lo_export(Oid lobjId, text *filename)
362387
*/
363388
while ((nbytes = inv_read(lobj, buf, BUFSIZE)) > 0)
364389
{
365-
tmp = write(fd, buf, nbytes);
390+
tmp = FileWrite(fd, buf, nbytes);
366391
if (tmp < nbytes)
367392
{
368393
elog(ERROR, "lo_export: error while writing \"%s\"",
@@ -371,7 +396,7 @@ lo_export(Oid lobjId, text *filename)
371396
}
372397

373398
inv_close(lobj);
374-
close(fd);
399+
FileClose(fd);
375400

376401
return 1;
377402
}

src/backend/libpq/crypt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Dec 17, 1997 - Todd A. Brandys
1010
* Orignal Version Completed.
1111
*
12-
* $Id: crypt.c,v 1.15 1999/02/13 23:15:42 momjian Exp $
12+
* $Id: crypt.c,v 1.16 1999/05/09 00:54:30 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -174,7 +174,7 @@ crypt_loadpwdfile()
174174
pwd_cache = (char **) realloc((void *) pwd_cache, sizeof(char *) * (pwd_cache_count + 1));
175175
pwd_cache[pwd_cache_count++] = pstrdup(buffer);
176176
}
177-
fclose(pwd_file);
177+
FreeFile(pwd_file);
178178

179179
/*
180180
* Now sort the entries in the cache for faster searching later.

src/backend/libpq/hba.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* wherein you authenticate a user by seeing what IP address the system
66
* says he comes from and possibly using ident).
77
*
8-
* $Id: hba.c,v 1.40 1999/04/16 04:59:03 tgl Exp $
8+
* $Id: hba.c,v 1.41 1999/05/09 00:54:30 tgl Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -966,9 +966,9 @@ GetCharSetByHost(char *TableName, int host, const char *DataDir)
966966
map_file = (char *) palloc(bufsize);
967967
snprintf(map_file, bufsize, "%s/%s", DataDir, CHARSET_FILE);
968968
#ifndef __CYGWIN32__
969-
file = fopen(map_file, "r");
969+
file = AllocateFile(map_file, "r");
970970
#else
971-
file = fopen(map_file, "rb");
971+
file = AllocateFile(map_file, "rb");
972972
#endif
973973
if (file == NULL)
974974
{
@@ -1049,7 +1049,7 @@ GetCharSetByHost(char *TableName, int host, const char *DataDir)
10491049
}
10501050
}
10511051
}
1052-
fclose(file);
1052+
FreeFile(file);
10531053
pfree(map_file);
10541054

10551055
for (i = 0; i < ChIndex; i++)

src/backend/utils/init/miscinit.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.26 1999/02/13 23:20:01 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.27 1999/05/09 00:54:30 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -339,9 +339,9 @@ SetCharSet()
339339
strlen(p) + 2) * sizeof(char));
340340
sprintf(map_file, "%s/%s", DataDir, p);
341341
#ifndef __CYGWIN32__
342-
file = fopen(map_file, "r");
342+
file = AllocateFile(map_file, "r");
343343
#else
344-
file = fopen(map_file, "rb");
344+
file = AllocateFile(map_file, "rb");
345345
#endif
346346
if (file == NULL)
347347
return;
@@ -376,7 +376,7 @@ SetCharSet()
376376
}
377377
}
378378
}
379-
fclose(file);
379+
FreeFile(file);
380380
free(map_file);
381381
}
382382
}

0 commit comments

Comments
 (0)