diff options
| author | Marc G. Fournier <scrappy@hub.org> | 1997-04-17 20:39:31 +0000 |
|---|---|---|
| committer | Marc G. Fournier <scrappy@hub.org> | 1997-04-17 20:39:31 +0000 |
| commit | cbaa98835c5c088ab23a2096ae2d3a6e78467bda (patch) | |
| tree | 3a2e2edd4851daa677bf66d0820488452970a4d9 /src | |
| parent | 8834795ebf68f0518f6498043e1c7f2abe81f8ec (diff) | |
| download | postgresql-cbaa98835c5c088ab23a2096ae2d3a6e78467bda.tar.gz | |
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.)
Diffstat (limited to 'src')
| -rw-r--r-- | src/backend/libpq/be-fsstubs.c | 22 | ||||
| -rw-r--r-- | src/interfaces/libpq/fe-connect.c | 3 |
2 files changed, 16 insertions, 9 deletions
diff --git a/src/backend/libpq/be-fsstubs.c b/src/backend/libpq/be-fsstubs.c index 37952be212..64b585af9a 100644 --- a/src/backend/libpq/be-fsstubs.c +++ b/src/backend/libpq/be-fsstubs.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/libpq/be-fsstubs.c,v 1.6 1997/03/18 21:29:21 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/backend/libpq/be-fsstubs.c,v 1.7 1997/04/17 20:39:31 scrappy Exp $ * * NOTES * This should be moved to a more appropriate place. It is here @@ -249,16 +249,19 @@ lo_import(text *filename) int nbytes, tmp; #define BUFSIZE 1024 char buf[BUFSIZE]; + char fnamebuf[8192]; LargeObjectDesc *lobj; Oid lobjOid; /* * open the file to be read in */ - fd = open(VARDATA(filename), O_RDONLY, 0666); + strncpy(fnamebuf, VARDATA(filename), VARSIZE(filename)); + fnamebuf[VARSIZE(filename)] = '\0'; + fd = open(fnamebuf, O_RDONLY, 0666); if (fd < 0) { /* error */ elog(WARN, "lo_import: can't open unix file\"%s\"\n", - VARDATA(filename)); + fnamebuf); } /* @@ -267,7 +270,7 @@ lo_import(text *filename) lobj = inv_create(INV_READ|INV_WRITE); if (lobj == NULL) { elog(WARN, "lo_import: can't create inv object for \"%s\"", - VARDATA(filename)); + fnamebuf); } /* @@ -283,7 +286,7 @@ lo_import(text *filename) tmp = inv_write(lobj, buf, nbytes); if (tmp < nbytes) { elog(WARN, "lo_import: error while reading \"%s\"", - VARDATA(filename)); + fnamebuf); } } @@ -304,6 +307,7 @@ lo_export(Oid lobjId, text *filename) int nbytes, tmp; #define BUFSIZE 1024 char buf[BUFSIZE]; + char fnamebuf[8192]; LargeObjectDesc *lobj; mode_t oumask; @@ -320,11 +324,13 @@ lo_export(Oid lobjId, text *filename) * open the file to be written to */ oumask = umask((mode_t) 0); - fd = open(VARDATA(filename), O_CREAT|O_WRONLY, 0666); + strncpy(fnamebuf, VARDATA(filename), VARSIZE(filename)); + fnamebuf[VARSIZE(filename)] = '\0'; + fd = open(fnamebuf, O_CREAT|O_WRONLY, 0666); (void) umask(oumask); if (fd < 0) { /* error */ elog(WARN, "lo_export: can't open unix file\"%s\"", - VARDATA(filename)); + fnamebuf); } /* @@ -334,7 +340,7 @@ lo_export(Oid lobjId, text *filename) tmp = write(fd, buf, nbytes); if (tmp < nbytes) { elog(WARN, "lo_export: error while writing \"%s\"", - VARDATA(filename)); + fnamebuf); } } diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index d1ebdb62c1..5fce9f2757 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.30 1997/04/16 06:29:19 vadim Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.31 1997/04/17 20:39:23 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -196,6 +196,7 @@ PQconnectdb(const char *conninfo) * Setup the conn structure * ---------- */ + conn->lobjfuncs = (PGlobjfuncs *) NULL; conn->Pfout = NULL; conn->Pfin = NULL; conn->Pfdebug = NULL; |
