Skip to content

Commit 0f679d2

Browse files
committed
Reject, in pg_dumpall, names containing CR or LF.
These characters prematurely terminate Windows shell command processing, causing the shell to execute a prefix of the intended command. The chief alternative to rejecting these characters was to bypass the Windows shell with CreateProcess(), but the ability to use such names has little value. Back-patch to 9.1 (all supported versions). This change formally revokes support for these characters in database names and roles names. Don't document this; the error message is self-explanatory, and too few users would benefit. A future major release may forbid creation of databases and roles so named. For now, check only at known weak points in pg_dumpall. Future commits will, without notice, reject affected names from other frontend programs. Also extend the restriction to pg_dumpall --dbname=CONNSTR arguments and --file arguments. Unlike the effects on role name arguments and database names, this does not reflect a broad policy change. A migration to CreateProcess() could lift these two restrictions. Reviewed by Peter Eisentraut. Security: CVE-2016-5424
1 parent 05abd3b commit 0f679d2

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/bin/pg_dump/pg_dumpall.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2117,6 +2117,12 @@ doConnStrQuoting(PQExpBuffer buf, const char *str)
21172117
/*
21182118
* Append the given string to the shell command being built in the buffer,
21192119
* with suitable shell-style quoting.
2120+
*
2121+
* Forbid LF or CR characters, which have scant practical use beyond designing
2122+
* security breaches. The Windows command shell is unusable as a conduit for
2123+
* arguments containing LF or CR characters. A future major release should
2124+
* reject those characters in CREATE ROLE and CREATE DATABASE, because use
2125+
* there eventually leads to errors here.
21202126
*/
21212127
static void
21222128
doShellQuoting(PQExpBuffer buf, const char *str)
@@ -2127,6 +2133,14 @@ doShellQuoting(PQExpBuffer buf, const char *str)
21272133
appendPQExpBufferChar(buf, '\'');
21282134
for (p = str; *p; p++)
21292135
{
2136+
if (*p == '\n' || *p == '\r')
2137+
{
2138+
fprintf(stderr,
2139+
_("shell command argument contains a newline or carriage return: \"%s\"\n"),
2140+
str);
2141+
exit(EXIT_FAILURE);
2142+
}
2143+
21302144
if (*p == '\'')
21312145
appendPQExpBuffer(buf, "'\"'\"'");
21322146
else
@@ -2138,6 +2152,14 @@ doShellQuoting(PQExpBuffer buf, const char *str)
21382152
appendPQExpBufferChar(buf, '"');
21392153
for (p = str; *p; p++)
21402154
{
2155+
if (*p == '\n' || *p == '\r')
2156+
{
2157+
fprintf(stderr,
2158+
_("shell command argument contains a newline or carriage return: \"%s\"\n"),
2159+
str);
2160+
exit(EXIT_FAILURE);
2161+
}
2162+
21412163
if (*p == '"')
21422164
appendPQExpBuffer(buf, "\\\"");
21432165
else

0 commit comments

Comments
 (0)