mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-09-30 12:51:22 +02:00
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.)
This commit is contained in:
parent
8834795ebf
commit
cbaa98835c
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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
|
* NOTES
|
||||||
* This should be moved to a more appropriate place. It is here
|
* This should be moved to a more appropriate place. It is here
|
||||||
@ -249,16 +249,19 @@ lo_import(text *filename)
|
|||||||
int nbytes, tmp;
|
int nbytes, tmp;
|
||||||
#define BUFSIZE 1024
|
#define BUFSIZE 1024
|
||||||
char buf[BUFSIZE];
|
char buf[BUFSIZE];
|
||||||
|
char fnamebuf[8192];
|
||||||
LargeObjectDesc *lobj;
|
LargeObjectDesc *lobj;
|
||||||
Oid lobjOid;
|
Oid lobjOid;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* open the file to be read in
|
* 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 */
|
if (fd < 0) { /* error */
|
||||||
elog(WARN, "lo_import: can't open unix file\"%s\"\n",
|
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);
|
lobj = inv_create(INV_READ|INV_WRITE);
|
||||||
if (lobj == NULL) {
|
if (lobj == NULL) {
|
||||||
elog(WARN, "lo_import: can't create inv object for \"%s\"",
|
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);
|
tmp = inv_write(lobj, buf, nbytes);
|
||||||
if (tmp < nbytes) {
|
if (tmp < nbytes) {
|
||||||
elog(WARN, "lo_import: error while reading \"%s\"",
|
elog(WARN, "lo_import: error while reading \"%s\"",
|
||||||
VARDATA(filename));
|
fnamebuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -304,6 +307,7 @@ lo_export(Oid lobjId, text *filename)
|
|||||||
int nbytes, tmp;
|
int nbytes, tmp;
|
||||||
#define BUFSIZE 1024
|
#define BUFSIZE 1024
|
||||||
char buf[BUFSIZE];
|
char buf[BUFSIZE];
|
||||||
|
char fnamebuf[8192];
|
||||||
LargeObjectDesc *lobj;
|
LargeObjectDesc *lobj;
|
||||||
mode_t oumask;
|
mode_t oumask;
|
||||||
|
|
||||||
@ -320,11 +324,13 @@ lo_export(Oid lobjId, text *filename)
|
|||||||
* open the file to be written to
|
* open the file to be written to
|
||||||
*/
|
*/
|
||||||
oumask = umask((mode_t) 0);
|
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);
|
(void) umask(oumask);
|
||||||
if (fd < 0) { /* error */
|
if (fd < 0) { /* error */
|
||||||
elog(WARN, "lo_export: can't open unix file\"%s\"",
|
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);
|
tmp = write(fd, buf, nbytes);
|
||||||
if (tmp < nbytes) {
|
if (tmp < nbytes) {
|
||||||
elog(WARN, "lo_export: error while writing \"%s\"",
|
elog(WARN, "lo_export: error while writing \"%s\"",
|
||||||
VARDATA(filename));
|
fnamebuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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
|
* Setup the conn structure
|
||||||
* ----------
|
* ----------
|
||||||
*/
|
*/
|
||||||
|
conn->lobjfuncs = (PGlobjfuncs *) NULL;
|
||||||
conn->Pfout = NULL;
|
conn->Pfout = NULL;
|
||||||
conn->Pfin = NULL;
|
conn->Pfin = NULL;
|
||||||
conn->Pfdebug = NULL;
|
conn->Pfdebug = NULL;
|
||||||
|
Loading…
Reference in New Issue
Block a user