Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4cdd81d

Browse files
committed
Sanitize newlines in object names in "pg_restore -l" output.
Commits89e0bac et al replaced newlines with spaces in object namesprinted in SQL comments, but we neglected to consider that the samenames are also printed by "pg_restore -l", and a newline would renderthe output unparseable by "pg_restore -L". Apply the same replacementin "-l" output. Since "pg_restore -L" doesn't actually examine anyobject names, only the dump ID field that starts each line, this isenough to fix things for its purposes.The previous fix was treated as a security issue, and we might havedone that here as well, except that the issue was reported publiclyto start with. Anyway it's hard to see how this could be exploitedfor SQL injection; "pg_restore -L" doesn't do much with the fileexcept parse it for leading integers.Per bug #14587 from Milos Urbanek. Back-patch to all supported versions.Discussion:https://postgr.es/m/20170310155318.1425.30483@wrigleys.postgresql.org
1 parentd0fef06 commit4cdd81d

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,8 @@ PrintTOCSummary(Archive *AHX)
10991099

11001100
ahprintf(AH,";\n; Archive created at %s\n",stamp_str);
11011101
ahprintf(AH,"; dbname: %s\n; TOC Entries: %d\n; Compression: %d\n",
1102-
AH->archdbname,AH->tocCount,AH->compression);
1102+
replace_line_endings(AH->archdbname),
1103+
AH->tocCount,AH->compression);
11031104

11041105
switch (AH->format)
11051106
{
@@ -1136,10 +1137,37 @@ PrintTOCSummary(Archive *AHX)
11361137
curSection=te->section;
11371138
if (ropt->verbose||
11381139
(_tocEntryRequired(te,curSection,ropt)& (REQ_SCHEMA |REQ_DATA))!=0)
1140+
{
1141+
char*sanitized_name;
1142+
char*sanitized_schema;
1143+
char*sanitized_owner;
1144+
1145+
/*
1146+
* As in _printTocEntry(), sanitize strings that might contain
1147+
* newlines, to ensure that each logical output line is in fact
1148+
* one physical output line. This prevents confusion when the
1149+
* file is read by "pg_restore -L". Note that we currently don't
1150+
* bother to quote names, meaning that the name fields aren't
1151+
* automatically parseable. "pg_restore -L" doesn't care because
1152+
* it only examines the dumpId field, but someday we might want to
1153+
* try harder.
1154+
*/
1155+
sanitized_name=replace_line_endings(te->tag);
1156+
if (te->namespace)
1157+
sanitized_schema=replace_line_endings(te->namespace);
1158+
else
1159+
sanitized_schema=pg_strdup("-");
1160+
sanitized_owner=replace_line_endings(te->owner);
1161+
11391162
ahprintf(AH,"%d; %u %u %s %s %s %s\n",te->dumpId,
11401163
te->catalogId.tableoid,te->catalogId.oid,
1141-
te->desc,te->namespace ?te->namespace :"-",
1142-
te->tag,te->owner);
1164+
te->desc,sanitized_schema,sanitized_name,
1165+
sanitized_owner);
1166+
1167+
free(sanitized_name);
1168+
free(sanitized_schema);
1169+
free(sanitized_owner);
1170+
}
11431171
if (ropt->verbose&&te->nDeps>0)
11441172
{
11451173
inti;
@@ -3495,8 +3523,9 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, bool isData, bool acl_pass)
34953523
}
34963524

34973525
/*
3498-
* Sanitize a string to be included in an SQL comment, by replacing any
3499-
* newlines with spaces.
3526+
* Sanitize a string to be included in an SQL comment or TOC listing,
3527+
* by replacing any newlines with spaces.
3528+
* The result is a freshly malloc'd string.
35003529
*/
35013530
staticchar*
35023531
replace_line_endings(constchar*str)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp