Fix segfault in pg_restore - Mailing list pgsql-patches

From Oliver Elphick
Subject Fix segfault in pg_restore
Date
Msg-id 1043346530.31735.445.camel@linda.lfix.co.uk
Whole thread Raw
Responses Re: Fix segfault in pg_restore  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-patches
In pg_restore, die_horribly() is sometimes called with AH a null
pointer.  If that happens, there is currently a segfault because the
code attempts to dereference an element in the AH structure
unconditionally:

$ pg_restore -Ft nonexistent
pg_restore: [tar archiver] could not open TOC file for input: No such
file or directory
Segmentation fault


This patch makes it dereference the structure only if AH is set.


Index: src/bin/pg_dump/pg_backup_archiver.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/bin/pg_dump/pg_backup_archiver.c,v
retrieving revision 1.65
diff -u -r1.65 pg_backup_archiver.c
--- src/bin/pg_dump/pg_backup_archiver.c    2003/01/13 04:28:55    1.65
+++ src/bin/pg_dump/pg_backup_archiver.c    2003/01/23 13:39:16
@@ -1379,14 +1379,15 @@
 _die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt, va_list ap)
 {
     _write_msg(modulename, fmt, ap);
-    if (AH->public.verbose)
-        write_msg(NULL, "*** aborted because of error\n");

-    if (AH)
+    if (AH) {
+        if (AH->public.verbose)
+            write_msg(NULL, "*** aborted because of error\n");
         if (AH->connection)
             PQfinish(AH->connection);
-    if (AH->blobConnection)
-        PQfinish(AH->blobConnection);
+        if (AH->blobConnection)
+            PQfinish(AH->blobConnection);
+    }

     exit(1);
 }
--
Oliver Elphick <olly@lfix.co.uk>
LFIX Limited


pgsql-patches by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: SEQUENCEs and NO MAXVALUE NO MINVALUE
Next
From: Bruno Wolff III
Date:
Subject: Cube enhancements for 7.4