8000 Reject, in pg_dumpall, names containing CR or LF. · s-monk/postgres@61c2cd8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 61c2cd8

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 ba8c408 commit 61c2cd8

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
@@ -1905,6 +1905,12 @@ doConnStrQuoting(PQExpBuffer buf, const char *str)
19051905
/*
19061906
* Append the given string to the shell command being built in the buffer,
19071907
* with suitable shell-style quoting.
1908+
*
1909+
* Forbid LF or CR characters, which have scant practical use beyond designing
1910+
* security breaches. The Windows command shell is unusable as a conduit for
1911+
* arguments containing LF or CR characters. A future major release should
1912+
* reject those characters in CREATE ROLE and CREATE DATABASE, because use
1913+
* there eventually leads to errors here.
19081914
*/
19091915
static void
19101916
doShellQuoting(PQExpBuffer buf, const char *str)
@@ -1915,6 +1921,14 @@ doShellQuoting(PQExpBuffer buf, const char *str)
19151921
appendPQExpBufferChar(buf, '\'');
19161922
for (p = str; *p; p++)
19171923
{
1924+
if (*p == '\n' || *p == '\r')
1925+
{
1926+
fprintf(stderr,
1927+
_("shell command argument contains a newline or carriage return: \"%s\"\n"),
1928+
str);
1929+
exit(EXIT_FAILURE);
1930+
}
1931+
19181932
if (*p == '\'')
19191933
appendPQExpBuffer(buf, "'\"'\"'");
19201934
else
@@ -1926,6 +1940,14 @@ doShellQuoting(PQExpBuffer buf, const char *str)
19261940
appendPQExpBufferChar(buf, '"');
19271941
for (p = str; *p; p++)
19281942
{
1943+
if (*p == '\n' || *p == '\r')
1944+
{
1945+
fprintf(stderr,
1946+
_("shell command argument contains a newline or carriage return: \"%s\"\n"),
1947+
str);
1948+
exit(EXIT_FAILURE);
1949+
}
1950+
19291951
if (*p == '"')
19301952
appendPQExpBuffer(buf, "\\\"");
19311953
else

0 commit comments

Comments
 (0)
0