Fix segfault in pg_restore

Started by Oliver Elphickover 23 years ago2 messagespatches
Jump to latest
#1Oliver Elphick
olly@lfix.co.uk

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

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Oliver Elphick (#1)
Re: Fix segfault in pg_restore

Oliver Elphick <olly@lfix.co.uk> writes:

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:

Patch applied in CVS HEAD and REL7_3 branch. Thanks.

regards, tom lane