aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2011-04-07 11:40:44 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2011-04-07 11:40:44 -0400
commit00a922906073314f9ba000c933eb6d2308c0a162 (patch)
tree5878716ee561444ea114e703e83edfbe5a7194e9 /src
parent93acf043b252b8f03cc573f70af39597019cd918 (diff)
downloadpostgresql-00a922906073314f9ba000c933eb6d2308c0a162.tar.gz
postgresql-00a922906073314f9ba000c933eb6d2308c0a162.zip
Fix SortTocFromFile() to cope with lines that are too long for its buffer.
The original coding supposed that a dump TOC file could never contain lines longer than 1K. The folly of that was exposed by a recent report from Per-Olov Esgard. We only really need to see the first dozen or two bytes of each line, since we're just trying to read off the numeric ID at the start of the line; so there's no need for a particularly huge buffer. What there is a need for is logic to not process continuation bufferloads. Back-patch to all supported branches, since it's always been like this.
Diffstat (limited to 'src')
-rw-r--r--src/bin/pg_dump/pg_backup_archiver.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c
index 5982d171a4a..453236f6d63 100644
--- a/src/bin/pg_dump/pg_backup_archiver.c
+++ b/src/bin/pg_dump/pg_backup_archiver.c
@@ -789,11 +789,8 @@ SortTocFromFile(Archive *AHX, RestoreOptions *ropt)
{
ArchiveHandle *AH = (ArchiveHandle *) AHX;
FILE *fh;
- char buf[1024];
- char *cmnt;
- char *endptr;
- DumpId id;
- TocEntry *te;
+ char buf[100];
+ bool incomplete_line;
TocEntry *tePrev;
/* Allocate space for the 'wanted' array, and init it */
@@ -809,8 +806,30 @@ SortTocFromFile(Archive *AHX, RestoreOptions *ropt)
die_horribly(AH, modulename, "could not open TOC file: %s\n",
strerror(errno));
+ incomplete_line = false;
while (fgets(buf, sizeof(buf), fh) != NULL)
{
+ bool prev_incomplete_line = incomplete_line;
+ int buflen;
+ char *cmnt;
+ char *endptr;
+ DumpId id;
+ TocEntry *te;
+
+ /*
+ * Some lines in the file might be longer than sizeof(buf). This is
+ * no problem, since we only care about the leading numeric ID which
+ * can be at most a few characters; but we have to skip continuation
+ * bufferloads when processing a long line.
+ */
+ buflen = strlen(buf);
+ if (buflen > 0 && buf[buflen - 1] == '\n')
+ incomplete_line = false;
+ else
+ incomplete_line = true;
+ if (prev_incomplete_line)
+ continue;
+
/* Truncate line at comment, if any */
cmnt = strchr(buf, ';');
if (cmnt != NULL)