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

Commitf39ddd8

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 parent8b358b4 commitf39ddd8

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
@@ -1104,7 +1104,8 @@ PrintTOCSummary(Archive *AHX)
11041104

11051105
ahprintf(AH,";\n; Archive created at %s\n",stamp_str);
11061106
ahprintf(AH,"; dbname: %s\n; TOC Entries: %d\n; Compression: %d\n",
1107-
AH->archdbname,AH->tocCount,AH->compression);
1107+
replace_line_endings(AH->archdbname),
1108+
AH->tocCount,AH->compression);
11081109

11091110
switch (AH->format)
11101111
{
@@ -1142,10 +1143,37 @@ PrintTOCSummary(Archive *AHX)
11421143
curSection=te->section;
11431144
if (ropt->verbose||
11441145
(_tocEntryRequired(te,curSection,ropt)& (REQ_SCHEMA |REQ_DATA))!=0)
1146+
{
1147+
char*sanitized_name;
1148+
char*sanitized_schema;
1149+
char*sanitized_owner;
1150+
1151+
/*
1152+
* As in _printTocEntry(), sanitize strings that might contain
1153+
* newlines, to ensure that each logical output line is in fact
1154+
* one physical output line. This prevents confusion when the
1155+
* file is read by "pg_restore -L". Note that we currently don't
1156+
* bother to quote names, meaning that the name fields aren't
1157+
* automatically parseable. "pg_restore -L" doesn't care because
1158+
* it only examines the dumpId field, but someday we might want to
1159+
* try harder.
1160+
*/
1161+
sanitized_name=replace_line_endings(te->tag);
1162+
if (te->namespace)
1163+
sanitized_schema=replace_line_endings(te->namespace);
1164+
else
1165+
sanitized_schema=pg_strdup("-");
1166+
sanitized_owner=replace_line_endings(te->owner);
1167+
11451168
ahprintf(AH,"%d; %u %u %s %s %s %s\n",te->dumpId,
11461169
te->catalogId.tableoid,te->catalogId.oid,
1147-
te->desc,te->namespace ?te->namespace :"-",
1148-
te->tag,te->owner);
1170+
te->desc,sanitized_schema,sanitized_name,
1171+
sanitized_owner);
1172+
1173+
free(sanitized_name);
1174+
free(sanitized_schema);
1175+
free(sanitized_owner);
1176+
}
11491177
if (ropt->verbose&&te->nDeps>0)
11501178
{
11511179
inti;
@@ -3531,8 +3559,9 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, bool isData, bool acl_pass)
35313559
}
35323560

35333561
/*
3534-
* Sanitize a string to be included in an SQL comment, by replacing any
3535-
* newlines with spaces.
3562+
* Sanitize a string to be included in an SQL comment or TOC listing,
3563+
* by replacing any newlines with spaces.
3564+
* The result is a freshly malloc'd string.
35363565
*/
35373566
staticchar*
35383567
replace_line_endings(constchar*str)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp