7
7
*
8
8
*
9
9
* 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 $
11
11
*
12
12
* NOTES
13
13
* This should be moved to a more appropriate place. It is here
@@ -99,7 +99,7 @@ lo_close(int fd)
99
99
{
100
100
MemoryContext currentContext ;
101
101
102
- if (fd >= MAX_LOBJ_FDS )
102
+ if (fd < 0 || fd >= MAX_LOBJ_FDS )
103
103
{
104
104
elog (ERROR , "lo_close: large obj descriptor (%d) out of range" , fd );
105
105
return -2 ;
@@ -131,14 +131,34 @@ lo_close(int fd)
131
131
int
132
132
lo_read (int fd , char * buf , int len )
133
133
{
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
+
135
145
return inv_read (cookies [fd ], buf , len );
136
146
}
137
147
138
148
int
139
149
lo_write (int fd , char * buf , int len )
140
150
{
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
+
142
162
return inv_write (cookies [fd ], buf , len );
143
163
}
144
164
@@ -149,11 +169,16 @@ lo_lseek(int fd, int offset, int whence)
149
169
MemoryContext currentContext ;
150
170
int ret ;
151
171
152
- if (fd >= MAX_LOBJ_FDS )
172
+ if (fd < 0 || fd >= MAX_LOBJ_FDS )
153
173
{
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 );
155
175
return -2 ;
156
176
}
177
+ if (cookies [fd ] == NULL )
178
+ {
179
+ elog (ERROR , "lo_lseek: invalid large obj descriptor (%d)" , fd );
180
+ return -3 ;
181
+ }
157
182
158
183
currentContext = MemoryContextSwitchTo ((MemoryContext ) fscxt );
159
184
@@ -197,7 +222,7 @@ lo_creat(int mode)
197
222
int
198
223
lo_tell (int fd )
199
224
{
200
- if (fd >= MAX_LOBJ_FDS )
225
+ if (fd < 0 || fd >= MAX_LOBJ_FDS )
201
226
{
202
227
elog (ERROR , "lo_tell: large object descriptor (%d) out of range" , fd );
203
228
return -2 ;
@@ -255,7 +280,7 @@ lowrite(int fd, struct varlena * wbuf)
255
280
Oid
256
281
lo_import (text * filename )
257
282
{
258
- int fd ;
283
+ File fd ;
259
284
int nbytes ,
260
285
tmp ;
261
286
@@ -269,13 +294,13 @@ lo_import(text *filename)
269
294
*/
270
295
StrNCpy (fnamebuf , VARDATA (filename ), VARSIZE (filename ) - VARHDRSZ + 1 );
271
296
#ifndef __CYGWIN32__
272
- fd = open (fnamebuf , O_RDONLY , 0666 );
297
+ fd = PathNameOpenFile (fnamebuf , O_RDONLY , 0666 );
273
298
#else
274
- fd = open (fnamebuf , O_RDONLY | O_BINARY , 0666 );
299
+ fd = PathNameOpenFile (fnamebuf , O_RDONLY | O_BINARY , 0666 );
275
300
#endif
276
301
if (fd < 0 )
277
302
{ /* 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" ,
279
304
fnamebuf );
280
305
}
281
306
@@ -298,7 +323,7 @@ lo_import(text *filename)
298
323
/*
299
324
* read in from the Unix file and write to the inversion file
300
325
*/
301
- while ((nbytes = read (fd , buf , BUFSIZE )) > 0 )
326
+ while ((nbytes = FileRead (fd , buf , BUFSIZE )) > 0 )
302
327
{
303
328
tmp = inv_write (lobj , buf , nbytes );
304
329
if (tmp < nbytes )
@@ -308,7 +333,7 @@ lo_import(text *filename)
308
333
}
309
334
}
310
335
311
- close (fd );
336
+ FileClose (fd );
312
337
inv_close (lobj );
313
338
314
339
return lobjOid ;
@@ -321,7 +346,7 @@ lo_import(text *filename)
321
346
int4
322
347
lo_export (Oid lobjId , text * filename )
323
348
{
324
- int fd ;
349
+ File fd ;
325
350
int nbytes ,
326
351
tmp ;
327
352
@@ -331,7 +356,7 @@ lo_export(Oid lobjId, text *filename)
331
356
mode_t oumask ;
332
357
333
358
/*
334
- * create an inversion "object"
359
+ * open the inversion "object"
335
360
*/
336
361
lobj = inv_open (lobjId , INV_READ );
337
362
if (lobj == NULL )
@@ -343,17 +368,17 @@ lo_export(Oid lobjId, text *filename)
343
368
/*
344
369
* open the file to be written to
345
370
*/
346
- oumask = umask ((mode_t ) 0 );
347
371
StrNCpy (fnamebuf , VARDATA (filename ), VARSIZE (filename ) - VARHDRSZ + 1 );
372
+ oumask = umask ((mode_t ) 0 );
348
373
#ifndef __CYGWIN32__
349
- fd = open (fnamebuf , O_CREAT | O_WRONLY | O_TRUNC , 0666 );
374
+ fd = PathNameOpenFile (fnamebuf , O_CREAT | O_WRONLY | O_TRUNC , 0666 );
350
375
#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 );
352
377
#endif
353
378
umask (oumask );
354
379
if (fd < 0 )
355
380
{ /* error */
356
- elog (ERROR , "lo_export: can't open unix file\"%s\"" ,
381
+ elog (ERROR , "lo_export: can't open unix file \"%s\"" ,
357
382
fnamebuf );
358
383
}
359
384
@@ -362,7 +387,7 @@ lo_export(Oid lobjId, text *filename)
362
387
*/
363
388
while ((nbytes = inv_read (lobj , buf , BUFSIZE )) > 0 )
364
389
{
365
- tmp = write (fd , buf , nbytes );
390
+ tmp = FileWrite (fd , buf , nbytes );
366
391
if (tmp < nbytes )
367
392
{
368
393
elog (ERROR , "lo_export: error while writing \"%s\"" ,
@@ -371,7 +396,7 @@ lo_export(Oid lobjId, text *filename)
371
396
}
372
397
373
398
inv_close (lobj );
374
- close (fd );
399
+ FileClose (fd );
375
400
376
401
return 1 ;
377
402
}
0 commit comments