From 832b6d00e9b7608ce21aff68abda50c400c5c7d6 Mon Sep 17 00:00:00 2001 From: Bruce Momjian <bruce@momjian.us> Date: Thu, 22 Mar 2007 19:42:02 +0000 Subject: [PATCH] Properly enforce pg_dump -F formation options; only single letter or full words support, per report from Mark Stosberg. --- src/bin/pg_dump/pg_dump.c | 59 ++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 90e78c36d15..d31c47b5832 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -12,7 +12,7 @@ * by PostgreSQL * * IDENTIFICATION - * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.461 2007/03/19 23:38:30 wieck Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.462 2007/03/22 19:42:02 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -476,38 +476,33 @@ main(int argc, char **argv) } /* open the output file */ - switch (format[0]) + if (strcasecmp(format, "a") == 0 || strcasecmp(format, "append") == 0) { - case 'a': - case 'A': - plainText = 1; - g_fout = CreateArchive(filename, archNull, 0, archModeAppend); - break; - - case 'c': - case 'C': - g_fout = CreateArchive(filename, archCustom, compressLevel, archModeWrite); - break; - - case 'f': - case 'F': - g_fout = CreateArchive(filename, archFiles, compressLevel, archModeWrite); - break; - - case 'p': - case 'P': - plainText = 1; - g_fout = CreateArchive(filename, archNull, 0, archModeWrite); - break; - - case 't': - case 'T': - g_fout = CreateArchive(filename, archTar, compressLevel, archModeWrite); - break; - - default: - write_msg(NULL, "invalid output format \"%s\" specified\n", format); - exit(1); + /* not documented */ + plainText = 1; + g_fout = CreateArchive(filename, archNull, 0, archModeAppend); + } + else if (strcasecmp(format, "c") == 0 || strcasecmp(format, "custom") == 0) + g_fout = CreateArchive(filename, archCustom, compressLevel, archModeWrite); + else if (strcasecmp(format, "f") == 0 || strcasecmp(format, "file") == 0) + { + /* + * Dump files into the current directory; for demonstration only, not + * documented. + */ + g_fout = CreateArchive(filename, archFiles, compressLevel, archModeWrite); + } + else if (strcasecmp(format, "p") == 0 || strcasecmp(format, "plain") == 0) + { + plainText = 1; + g_fout = CreateArchive(filename, archNull, 0, archModeWrite); + } + else if (strcasecmp(format, "t") == 0 || strcasecmp(format, "tar") == 0) + g_fout = CreateArchive(filename, archTar, compressLevel, archModeWrite); + else + { + write_msg(NULL, "invalid output format \"%s\" specified\n", format); + exit(1); } if (g_fout == NULL) -- GitLab