]> granicus.if.org Git - postgresql/commitdiff
From: Raymond Toy <toy@rtp.ericsson.se>
authorMarc G. Fournier <scrappy@hub.org>
Thu, 17 Apr 1997 20:39:31 +0000 (20:39 +0000)
committerMarc G. Fournier <scrappy@hub.org>
Thu, 17 Apr 1997 20:39:31 +0000 (20:39 +0000)
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.)

src/backend/libpq/be-fsstubs.c
src/interfaces/libpq/fe-connect.c

index 37952be21208fe20a3a3b0b57b7ffaf9c740ce3d..64b585af9a56a0ec77686fd8826ca8bd9d996f1a 100644 (file)
@@ -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);
        }
     }
 
index d1ebdb62c1e8b3307085359e5c3ade209e604f13..5fce9f275752deef7ec6df8099f860ffeec97b52 100644 (file)
@@ -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;