Skip to content

Commit 1f79360

Browse files
committed
Quote database name properly when invoking pg_dump. Per report from
Christopher Kings-Lynne.
1 parent fadcb01 commit 1f79360

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/bin/pg_dump/pg_dumpall.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1994, Regents of the University of California
77
*
88
*
9-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.9 2002/10/18 22:05:36 petere Exp $
9+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.10 2002/11/22 03:09:43 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -589,17 +589,31 @@ static int
589589
runPgDump(const char *dbname)
590590
{
591591
PQExpBuffer cmd = createPQExpBuffer();
592+
const char *p;
592593
int ret;
593594

594-
appendPQExpBuffer(cmd, "%s %s -X use-set-session-authorization -Fp %s",
595-
pgdumploc, pgdumpopts->data, dbname);
595+
appendPQExpBuffer(cmd, "%s %s -X use-set-session-authorization -Fp '",
596+
pgdumploc, pgdumpopts->data);
597+
598+
/* Shell quoting is not quite like SQL quoting, so can't use fmtId */
599+
for (p = dbname; *p; p++)
600+
{
601+
if (*p == '\'')
602+
appendPQExpBuffer(cmd, "'\"'\"'");
603+
else
604+
appendPQExpBufferChar(cmd, *p);
605+
}
606+
607+
appendPQExpBufferChar(cmd, '\'');
608+
596609
if (verbose)
597610
fprintf(stderr, _("%s: running %s\n"), progname, cmd->data);
598611

599612
fflush(stdout);
600613
fflush(stderr);
601614

602615
ret = system(cmd->data);
616+
603617
destroyPQExpBuffer(cmd);
604618

605619
return ret;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy