Skip to content

Commit f9ad8a2

Browse files
committed
Guard against duplicate IDs in input file in SortTocFromFile().
Per report from Brian Hackett.
1 parent 5185cc8 commit f9ad8a2

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.108 2005/04/30 08:08:51 neilc Exp $
18+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.109 2005/05/17 17:30:29 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -891,24 +891,21 @@ SortTocFromFile(Archive *AHX, RestoreOptions *ropt)
891891
if (!fh)
892892
die_horribly(AH, modulename, "could not open TOC file\n");
893893

894-
while (fgets(buf, 1024, fh) != NULL)
894+
while (fgets(buf, sizeof(buf), fh) != NULL)
895895
{
896-
/* Find a comment */
896+
/* Truncate line at comment, if any */
897897
cmnt = strchr(buf, ';');
898-
if (cmnt == buf)
899-
continue;
900-
901-
/* End string at comment */
902898
if (cmnt != NULL)
903899
cmnt[0] = '\0';
904900

905-
/* Skip if all spaces */
906-
if (strspn(buf, " \t") == strlen(buf))
901+
/* Ignore if all blank */
902+
if (strspn(buf, " \t\r") == strlen(buf))
907903
continue;
908904

909-
/* Get an ID */
905+
/* Get an ID, check it's valid and not already seen */
910906
id = strtol(buf, &endptr, 10);
911-
if (endptr == buf || id <= 0 || id > AH->maxDumpId)
907+
if (endptr == buf || id <= 0 || id > AH->maxDumpId ||
908+
ropt->idWanted[id - 1])
912909
{
913910
write_msg(modulename, "WARNING: line ignored: %s\n", buf);
914911
continue;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy