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

Commit79f21b3

Browse files
committed
Fix pg_dumpall with database names containing =
If a database name contained a '=' character, pg_dumpall failed. The problemwas in the way pg_dumpall passes the database name to pg_dump on thecommand line. If it contained a '=' character, pg_dump would interpret itas a libpq connection string instead of a plain database name.To fix, pass the database name to pg_dump as a connection string,"dbname=foo", with the database name escaped if necessary.Back-patch to all supported branches.
1 parent5c97528 commit79f21b3

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

‎src/bin/pg_dump/pg_dumpall.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ static void makeAlterConfigCommand(PGconn *conn, const char *arrayitem,
4949
staticvoiddumpDatabases(PGconn*conn);
5050
staticvoiddumpTimestamp(char*msg);
5151
staticvoiddoShellQuoting(PQExpBufferbuf,constchar*str);
52+
staticvoiddoConnStrQuoting(PQExpBufferbuf,constchar*str);
5253

5354
staticintrunPgDump(constchar*dbname);
5455
staticvoidbuildShSecLabels(PGconn*conn,constchar*catalog_name,
@@ -1619,6 +1620,7 @@ dumpDatabases(PGconn *conn)
16191620
staticint
16201621
runPgDump(constchar*dbname)
16211622
{
1623+
PQExpBufferconnstr=createPQExpBuffer();
16221624
PQExpBuffercmd=createPQExpBuffer();
16231625
intret;
16241626

@@ -1634,7 +1636,17 @@ runPgDump(const char *dbname)
16341636
else
16351637
appendPQExpBuffer(cmd," -Fp ");
16361638

1637-
doShellQuoting(cmd,dbname);
1639+
/*
1640+
* Construct a connection string from the database name, like
1641+
* dbname='<database name>'. pg_dump would usually also accept the
1642+
* database name as is, but if it contains any = characters, it would
1643+
* incorrectly treat it as a connection string.
1644+
*/
1645+
appendPQExpBuffer(connstr,"dbname='");
1646+
doConnStrQuoting(connstr,dbname);
1647+
appendPQExpBuffer(connstr,"'");
1648+
1649+
doShellQuoting(cmd,connstr->data);
16381650

16391651
appendPQExpBuffer(cmd,"%s",SYSTEMQUOTE);
16401652

@@ -1647,6 +1659,7 @@ runPgDump(const char *dbname)
16471659
ret=system(cmd->data);
16481660

16491661
destroyPQExpBuffer(cmd);
1662+
destroyPQExpBuffer(connstr);
16501663

16511664
returnret;
16521665
}
@@ -1886,6 +1899,25 @@ dumpTimestamp(char *msg)
18861899
}
18871900

18881901

1902+
/*
1903+
* Append the given string to the buffer, with suitable quoting for passing
1904+
* the string as a value, in a keyword/pair value in a libpq connection
1905+
* string
1906+
*/
1907+
staticvoid
1908+
doConnStrQuoting(PQExpBufferbuf,constchar*str)
1909+
{
1910+
while (*str)
1911+
{
1912+
/* ' and \ must be escaped by to \' and \\ */
1913+
if (*str=='\''||*str=='\\')
1914+
appendPQExpBufferChar(buf,'\\');
1915+
1916+
appendPQExpBufferChar(buf,*str);
1917+
str++;
1918+
}
1919+
}
1920+
18891921
/*
18901922
* Append the given string to the shell command being built in the buffer,
18911923
* with suitable shell-style quoting.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp