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

Commitf435cd1

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 parent2930c05 commitf435cd1

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
@@ -50,6 +50,7 @@ static void makeAlterConfigCommand(PGconn *conn, const char *arrayitem,
5050
staticvoiddumpDatabases(PGconn*conn);
5151
staticvoiddumpTimestamp(char*msg);
5252
staticvoiddoShellQuoting(PQExpBufferbuf,constchar*str);
53+
staticvoiddoConnStrQuoting(PQExpBufferbuf,constchar*str);
5354

5455
staticintrunPgDump(constchar*dbname);
5556
staticvoidbuildShSecLabels(PGconn*conn,constchar*catalog_name,
@@ -1629,6 +1630,7 @@ dumpDatabases(PGconn *conn)
16291630
staticint
16301631
runPgDump(constchar*dbname)
16311632
{
1633+
PQExpBufferconnstr=createPQExpBuffer();
16321634
PQExpBuffercmd=createPQExpBuffer();
16331635
intret;
16341636

@@ -1644,7 +1646,17 @@ runPgDump(const char *dbname)
16441646
else
16451647
appendPQExpBuffer(cmd," -Fp ");
16461648

1647-
doShellQuoting(cmd,dbname);
1649+
/*
1650+
* Construct a connection string from the database name, like
1651+
* dbname='<database name>'. pg_dump would usually also accept the
1652+
* database name as is, but if it contains any = characters, it would
1653+
* incorrectly treat it as a connection string.
1654+
*/
1655+
appendPQExpBuffer(connstr,"dbname='");
1656+
doConnStrQuoting(connstr,dbname);
1657+
appendPQExpBuffer(connstr,"'");
1658+
1659+
doShellQuoting(cmd,connstr->data);
16481660

16491661
appendPQExpBuffer(cmd,"%s",SYSTEMQUOTE);
16501662

@@ -1657,6 +1669,7 @@ runPgDump(const char *dbname)
16571669
ret=system(cmd->data);
16581670

16591671
destroyPQExpBuffer(cmd);
1672+
destroyPQExpBuffer(connstr);
16601673

16611674
returnret;
16621675
}
@@ -1896,6 +1909,25 @@ dumpTimestamp(char *msg)
18961909
}
18971910

18981911

1912+
/*
1913+
* Append the given string to the buffer, with suitable quoting for passing
1914+
* the string as a value, in a keyword/pair value in a libpq connection
1915+
* string
1916+
*/
1917+
staticvoid
1918+
doConnStrQuoting(PQExpBufferbuf,constchar*str)
1919+
{
1920+
while (*str)
1921+
{
1922+
/* ' and \ must be escaped by to \' and \\ */
1923+
if (*str=='\''||*str=='\\')
1924+
appendPQExpBufferChar(buf,'\\');
1925+
1926+
appendPQExpBufferChar(buf,*str);
1927+
str++;
1928+
}
1929+
}
1930+
18991931
/*
19001932
* Append the given string to the shell command being built in the buffer,
19011933
* with suitable shell-style quoting.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp