From 1f793609075fe416e5a6df9f6494240c0e1ee640 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 22 Nov 2002 03:09:43 +0000 Subject: [PATCH] Quote database name properly when invoking pg_dump. Per report from Christopher Kings-Lynne. --- src/bin/pg_dump/pg_dumpall.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index 9de608d406..0c4bad7e06 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * - * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.9 2002/10/18 22:05:36 petere Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.10 2002/11/22 03:09:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -589,10 +589,23 @@ static int runPgDump(const char *dbname) { PQExpBuffer cmd = createPQExpBuffer(); + const char *p; int ret; - appendPQExpBuffer(cmd, "%s %s -X use-set-session-authorization -Fp %s", - pgdumploc, pgdumpopts->data, dbname); + appendPQExpBuffer(cmd, "%s %s -X use-set-session-authorization -Fp '", + pgdumploc, pgdumpopts->data); + + /* Shell quoting is not quite like SQL quoting, so can't use fmtId */ + for (p = dbname; *p; p++) + { + if (*p == '\'') + appendPQExpBuffer(cmd, "'\"'\"'"); + else + appendPQExpBufferChar(cmd, *p); + } + + appendPQExpBufferChar(cmd, '\''); + if (verbose) fprintf(stderr, _("%s: running %s\n"), progname, cmd->data); @@ -600,6 +613,7 @@ runPgDump(const char *dbname) fflush(stderr); ret = system(cmd->data); + destroyPQExpBuffer(cmd); return ret;