Guard against duplicate IDs in input file in SortTocFromFile().
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 17 May 2005 17:31:24 +0000 (17:31 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 17 May 2005 17:31:24 +0000 (17:31 +0000)
Per report from Brian Hackett.

src/bin/pg_dump/pg_backup_archiver.c

index 39cabdbac66566e842d6f941f4af95070366b83d..839535f8353628b0117c5fedd0b4091d69a6f472 100644 (file)
@@ -15,7 +15,7 @@
  *
  *
  * IDENTIFICATION
- *     $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.42.2.1 2005/04/30 09:08:14 neilc Exp $
+ *     $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.42.2.2 2005/05/17 17:31:24 tgl Exp $
  *
  * Modifications - 28-Jun-2000 - pjw@rhyme.com.au
  *
@@ -982,7 +982,7 @@ 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 */
        cmnt = strchr(buf, ';');
@@ -1010,10 +1010,13 @@ SortTocFromFile(Archive *AHX, RestoreOptions *ropt)
        if (!te)
            die_horribly(AH, modulename, "could not find entry for id %d\n", id);
 
-       ropt->idWanted[id - 1] = 1;
+       if (!ropt->idWanted[id - 1])
+       {
+           ropt->idWanted[id - 1] = 1;
 
-       _moveAfter(AH, tePrev, te);
-       tePrev = te;
+           _moveAfter(AH, tePrev, te);
+           tePrev = te;
+       }
    }
 
    if (fclose(fh) != 0)