Skip to content

Commit cbaa988

Browse files
committed
From: Raymond Toy <toy@rtp.ericsson.se>
Subject: [PATCHES] 970417: some large object patches Two patches here, made against 970417. Both have to do with large objects: 1. lobjfuncs was not initialized in PQconnectdb. This causes failure later if large objects are used. (Someone already caught this error in PQsetdb.) 2. Postgres functions lo_import and lo_export sometimes produce garbage for the file names because the filename strings aren't always terminated by \0. (VARDATA isn't necessarily null terminated.)
1 parent 8834795 commit cbaa988

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/backend/libpq/be-fsstubs.c

Lines changed: 14 additions & 8 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.6 1997/03/18 21:29:21 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/libpq/be-fsstubs.c,v 1.7 1997/04/17 20:39:31 scrappy Exp $
1111
*
1212
* NOTES
1313
* This should be moved to a more appropriate place. It is here
@@ -249,16 +249,19 @@ lo_import(text *filename)
249249
int nbytes, tmp;
250250
#define BUFSIZE 1024
251251
char buf[BUFSIZE];
252+
char fnamebuf[8192];
252253
LargeObjectDesc *lobj;
253254
Oid lobjOid;
254255

255256
/*
256257
* open the file to be read in
257258
*/
258-
fd = open(VARDATA(filename), O_RDONLY, 0666);
259+
strncpy(fnamebuf, VARDATA(filename), VARSIZE(filename));
260+
fnamebuf[VARSIZE(filename)] = '\0';
261+
fd = open(fnamebuf, O_RDONLY, 0666);
259262
if (fd < 0) { /* error */
260263
elog(WARN, "lo_import: can't open unix file\"%s\"\n",
261-
VARDATA(filename));
264+
fnamebuf);
262265
}
263266

264267
/*
@@ -267,7 +270,7 @@ lo_import(text *filename)
267270
lobj = inv_create(INV_READ|INV_WRITE);
268271
if (lobj == NULL) {
269272
elog(WARN, "lo_import: can't create inv object for \"%s\"",
270-
VARDATA(filename));
273+
fnamebuf);
271274
}
272275

273276
/*
@@ -283,7 +286,7 @@ lo_import(text *filename)
283286
tmp = inv_write(lobj, buf, nbytes);
284287
if (tmp < nbytes) {
285288
elog(WARN, "lo_import: error while reading \"%s\"",
286-
VARDATA(filename));
289+
fnamebuf);
287290
}
288291
}
289292

@@ -304,6 +307,7 @@ lo_export(Oid lobjId, text *filename)
304307
int nbytes, tmp;
305308
#define BUFSIZE 1024
306309
char buf[BUFSIZE];
310+
char fnamebuf[8192];
307311
LargeObjectDesc *lobj;
308312
mode_t oumask;
309313

@@ -320,11 +324,13 @@ lo_export(Oid lobjId, text *filename)
320324
* open the file to be written to
321325
*/
322326
oumask = umask((mode_t) 0);
323-
fd = open(VARDATA(filename), O_CREAT|O_WRONLY, 0666);
327+
strncpy(fnamebuf, VARDATA(filename), VARSIZE(filename));
328+
fnamebuf[VARSIZE(filename)] = '\0';
329+
fd = open(fnamebuf, O_CREAT|O_WRONLY, 0666);
324330
(void) umask(oumask);
325331
if (fd < 0) { /* error */
326332
elog(WARN, "lo_export: can't open unix file\"%s\"",
327-
VARDATA(filename));
333+
fnamebuf);
328334
}
329335

330336
/*
@@ -334,7 +340,7 @@ lo_export(Oid lobjId, text *filename)
334340
tmp = write(fd, buf, nbytes);
335341
if (tmp < nbytes) {
336342
elog(WARN, "lo_export: error while writing \"%s\"",
337-
VARDATA(filename));
343+
fnamebuf);
338344
}
339345
}
340346

src/interfaces/libpq/fe-connect.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.30 1997/04/16 06:29:19 vadim Exp $
10+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.31 1997/04/17 20:39:23 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -196,6 +196,7 @@ PQconnectdb(const char *conninfo)
196196
* Setup the conn structure
197197
* ----------
198198
*/
199+
conn->lobjfuncs = (PGlobjfuncs *) NULL;
199200
conn->Pfout = NULL;
200201
conn->Pfin = NULL;
201202
conn->Pfdebug = NULL;

0 commit comments

Comments
 (0)