aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2005-05-17 17:30:41 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2005-05-17 17:30:41 +0000
commit626be474d3a0328f06dbc2ff0838c10aaa1ae2bf (patch)
treeb22de606c6bb3d913aef9eaeb33809504d7fb032 /src
parentba5684691c207d0c09313b7680ffc69d76c03fff (diff)
downloadpostgresql-626be474d3a0328f06dbc2ff0838c10aaa1ae2bf.tar.gz
postgresql-626be474d3a0328f06dbc2ff0838c10aaa1ae2bf.zip
Guard against duplicate IDs in input file in SortTocFromFile().
Per report from Brian Hackett.
Diffstat (limited to 'src')
-rw-r--r--src/bin/pg_dump/pg_backup_archiver.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c
index e814a3cc8a1..0487ce7f50c 100644
--- a/src/bin/pg_dump/pg_backup_archiver.c
+++ b/src/bin/pg_dump/pg_backup_archiver.c
@@ -15,7 +15,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.101.4.6 2005/04/30 08:19:44 neilc Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.101.4.7 2005/05/17 17:30:41 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -891,24 +891,21 @@ SortTocFromFile(Archive *AHX, RestoreOptions *ropt)
if (!fh)
die_horribly(AH, modulename, "could not open TOC file\n");
- while (fgets(buf, 1024, fh) != NULL)
+ while (fgets(buf, sizeof(buf), fh) != NULL)
{
- /* Find a comment */
+ /* Truncate line at comment, if any */
cmnt = strchr(buf, ';');
- if (cmnt == buf)
- continue;
-
- /* End string at comment */
if (cmnt != NULL)
cmnt[0] = '\0';
- /* Skip if all spaces */
- if (strspn(buf, " \t") == strlen(buf))
+ /* Ignore if all blank */
+ if (strspn(buf, " \t\r") == strlen(buf))
continue;
- /* Get an ID */
+ /* Get an ID, check it's valid and not already seen */
id = strtol(buf, &endptr, 10);
- if (endptr == buf || id <= 0 || id > AH->maxDumpId)
+ if (endptr == buf || id <= 0 || id > AH->maxDumpId ||
+ ropt->idWanted[id - 1])
{
write_msg(modulename, "WARNING: line ignored: %s\n", buf);
continue;