]> granicus.if.org Git - postgresql/commitdiff
In our source code, make a copy of getopt's 'optarg' string arguments,
authorBruce Momjian <bruce@momjian.us>
Fri, 12 Oct 2012 17:35:40 +0000 (13:35 -0400)
committerBruce Momjian <bruce@momjian.us>
Fri, 12 Oct 2012 17:35:43 +0000 (13:35 -0400)
rather than just storing a pointer.

20 files changed:
contrib/pg_archivecleanup/pg_archivecleanup.c
contrib/pg_standby/pg_standby.c
contrib/pgbench/pgbench.c
src/backend/bootstrap/bootstrap.c
src/backend/postmaster/postmaster.c
src/bin/pg_dump/pg_dump.c
src/bin/pg_dump/pg_dumpall.c
src/bin/pg_dump/pg_restore.c
src/bin/psql/startup.c
src/bin/scripts/clusterdb.c
src/bin/scripts/createdb.c
src/bin/scripts/createlang.c
src/bin/scripts/createuser.c
src/bin/scripts/dropdb.c
src/bin/scripts/droplang.c
src/bin/scripts/dropuser.c
src/bin/scripts/reindexdb.c
src/bin/scripts/vacuumdb.c
src/interfaces/ecpg/preproc/ecpg.c
src/timezone/zic.c

index 8f77998de12f95f41bb95c3e05a14de6cdf18047..e97a11cb49a8519ba2ba0b5416a333a6a2a04309 100644 (file)
@@ -299,7 +299,7 @@ main(int argc, char **argv)
                                dryrun = true;
                                break;
                        case 'x':
-                               additional_ext = optarg;                /* Extension to remove from
+                               additional_ext = strdup(optarg);                /* Extension to remove from
                                                                                                 * xlogfile names */
                                break;
                        default:
index 84941ede137a7cb30f979ef584038edb00a48c46..659bd50da7d93f4730af7789fc02e9404a15c92c 100644 (file)
@@ -643,7 +643,7 @@ main(int argc, char **argv)
                                }
                                break;
                        case 't':                       /* Trigger file */
-                               triggerPath = optarg;
+                               triggerPath = strdup(optarg);
                                break;
                        case 'w':                       /* Max wait time */
                                maxwaittime = atoi(optarg);
index c399d59d25b448a92c6b3df23c02d149c2ab5434..5d48aeeae476e1a09acc64497b4adf45e063aadc 100644 (file)
@@ -1995,7 +1995,7 @@ main(int argc, char **argv)
                                is_init_mode++;
                                break;
                        case 'h':
-                               pghost = optarg;
+                               pghost = pg_strdup(optarg);
                                break;
                        case 'n':
                                is_no_vacuum++;
@@ -2004,7 +2004,7 @@ main(int argc, char **argv)
                                do_vacuum_accounts++;
                                break;
                        case 'p':
-                               pgport = optarg;
+                               pgport = pg_strdup(optarg);
                                break;
                        case 'd':
                                debug++;
@@ -2090,14 +2090,14 @@ main(int argc, char **argv)
                                }
                                break;
                        case 'U':
-                               login = optarg;
+                               login = pg_strdup(optarg);
                                break;
                        case 'l':
                                use_log = true;
                                break;
                        case 'f':
                                ttype = 3;
-                               filename = optarg;
+                               filename = pg_strdup(optarg);
                                if (process_file(filename) == false || *sql_files[num_files - 1] == NULL)
                                        exit(1);
                                break;
@@ -2143,10 +2143,10 @@ main(int argc, char **argv)
                                /* This covers long options which take no argument. */
                                break;
                        case 2:                         /* tablespace */
-                               tablespace = optarg;
+                               tablespace = pg_strdup(optarg);
                                break;
                        case 3:                         /* index-tablespace */
-                               index_tablespace = optarg;
+                               index_tablespace = pg_strdup(optarg);
                                break;
                        case 4:
                                sample_rate = atof(optarg);
index 34ddebbc0b97bf402ef85d739556317770b46f01..11086e2964b2af750d2a357aa94fb145b4d070bc 100644 (file)
@@ -241,7 +241,7 @@ AuxiliaryProcessMain(int argc, char *argv[])
                                SetConfigOption("shared_buffers", optarg, PGC_POSTMASTER, PGC_S_ARGV);
                                break;
                        case 'D':
-                               userDoption = optarg;
+                               userDoption = strdup(optarg);
                                break;
                        case 'd':
                                {
index e73caa8b294317ce23885909dd276b7267c901dd..dfe40492d27f3bde71024088ec069478a8c4b602 100644 (file)
@@ -570,11 +570,11 @@ PostmasterMain(int argc, char *argv[])
                                break;
 
                        case 'C':
-                               output_config_variable = optarg;
+                               output_config_variable = strdup(optarg);
                                break;
 
                        case 'D':
-                               userDoption = optarg;
+                               userDoption = strdup(optarg);
                                break;
 
                        case 'd':
index 9920d967241b07a150507604eac98890c64459a8..dd2019a1fb70f0d7ac6a27bb854a4d71e6de05f4 100644 (file)
@@ -409,19 +409,19 @@ main(int argc, char **argv)
                                break;
 
                        case 'E':                       /* Dump encoding */
-                               dumpencoding = optarg;
+                               dumpencoding = pg_strdup(optarg);
                                break;
 
                        case 'f':
-                               filename = optarg;
+                               filename = pg_strdup(optarg);
                                break;
 
                        case 'F':
-                               format = optarg;
+                               format = pg_strdup(optarg);
                                break;
 
                        case 'h':                       /* server host */
-                               pghost = optarg;
+                               pghost = pg_strdup(optarg);
                                break;
 
                        case 'i':
@@ -446,7 +446,7 @@ main(int argc, char **argv)
                                break;
 
                        case 'p':                       /* server port */
-                               pgport = optarg;
+                               pgport = pg_strdup(optarg);
                                break;
 
                        case 'R':
@@ -471,7 +471,7 @@ main(int argc, char **argv)
                                break;
 
                        case 'U':
-                               username = optarg;
+                               username = pg_strdup(optarg);
                                break;
 
                        case 'v':                       /* verbose */
@@ -499,11 +499,11 @@ main(int argc, char **argv)
                                break;
 
                        case 2:                         /* lock-wait-timeout */
-                               lockWaitTimeout = optarg;
+                               lockWaitTimeout = pg_strdup(optarg);
                                break;
 
                        case 3:                         /* SET ROLE */
-                               use_role = optarg;
+                               use_role = pg_strdup(optarg);
                                break;
 
                        case 4:                         /* exclude table(s) data */
index 10ce2223df4a57253f4906219fd96f31593387ff..ca95bad1cc002288ea3f0c6484e71f26f54a0cee 100644 (file)
@@ -200,7 +200,7 @@ main(int argc, char *argv[])
                                break;
 
                        case 'f':
-                               filename = optarg;
+                               filename = pg_strdup(optarg);
                                appendPQExpBuffer(pgdumpopts, " -f ");
                                doShellQuoting(pgdumpopts, filename);
                                break;
@@ -210,7 +210,7 @@ main(int argc, char *argv[])
                                break;
 
                        case 'h':
-                               pghost = optarg;
+                               pghost = pg_strdup(optarg);
                                appendPQExpBuffer(pgdumpopts, " -h ");
                                doShellQuoting(pgdumpopts, pghost);
                                break;
@@ -220,7 +220,7 @@ main(int argc, char *argv[])
                                break;
 
                        case 'l':
-                               pgdb = optarg;
+                               pgdb = pg_strdup(optarg);
                                break;
 
                        case 'o':
@@ -232,7 +232,7 @@ main(int argc, char *argv[])
                                break;
 
                        case 'p':
-                               pgport = optarg;
+                               pgport = pg_strdup(optarg);
                                appendPQExpBuffer(pgdumpopts, " -p ");
                                doShellQuoting(pgdumpopts, pgport);
                                break;
@@ -255,7 +255,7 @@ main(int argc, char *argv[])
                                break;
 
                        case 'U':
-                               pguser = optarg;
+                               pguser = pg_strdup(optarg);
                                appendPQExpBuffer(pgdumpopts, " -U ");
                                doShellQuoting(pgdumpopts, pguser);
                                break;
@@ -289,7 +289,7 @@ main(int argc, char *argv[])
                                break;
 
                        case 3:
-                               use_role = optarg;
+                               use_role = pg_strdup(optarg);
                                appendPQExpBuffer(pgdumpopts, " --role ");
                                doShellQuoting(pgdumpopts, use_role);
                                break;
index f6c835be0d123de57cd2336851a51faae4bfcda9..49d799b95300792bddf6f9ec25f338e2877b3738 100644 (file)
@@ -238,7 +238,7 @@ main(int argc, char **argv)
                                break;
 
                        case 'U':
-                               opts->username = optarg;
+                               opts->username = pg_strdup(optarg);
                                break;
 
                        case 'v':                       /* verbose */
@@ -270,7 +270,7 @@ main(int argc, char **argv)
                                break;
 
                        case 2:                         /* SET ROLE */
-                               opts->use_role = optarg;
+                               opts->use_role = pg_strdup(optarg);
                                break;
 
                        case 3:                         /* section */
index 3fb12c94522c2a93f9ffb2e9711e4bd627a2261d..1fcc47fad35fbb3b70cdc13f32c5b487eca8c416 100644 (file)
@@ -411,7 +411,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
                                pset.popt.topt.format = PRINT_UNALIGNED;
                                break;
                        case 'c':
-                               options->action_string = optarg;
+                               options->action_string = pg_strdup(optarg);
                                if (optarg[0] == '\\')
                                {
                                        options->action = ACT_SINGLE_SLASH;
@@ -421,7 +421,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
                                        options->action = ACT_SINGLE_QUERY;
                                break;
                        case 'd':
-                               options->dbname = optarg;
+                               options->dbname = pg_strdup(optarg);
                                break;
                        case 'e':
                                SetVariable(pset.vars, "ECHO", "queries");
@@ -431,14 +431,14 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
                                break;
                        case 'f':
                                options->action = ACT_FILE;
-                               options->action_string = optarg;
+                               options->action_string = pg_strdup(optarg);
                                break;
                        case 'F':
                                pset.popt.topt.fieldSep.separator = pg_strdup(optarg);
                                pset.popt.topt.fieldSep.separator_zero = false;
                                break;
                        case 'h':
-                               options->host = optarg;
+                               options->host = pg_strdup(optarg);
                                break;
                        case 'H':
                                pset.popt.topt.format = PRINT_HTML;
@@ -447,7 +447,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
                                options->action = ACT_LIST_DB;
                                break;
                        case 'L':
-                               options->logfilename = optarg;
+                               options->logfilename = pg_strdup(optarg);
                                break;
                        case 'n':
                                options->no_readline = true;
@@ -456,7 +456,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
                                setQFout(optarg);
                                break;
                        case 'p':
-                               options->port = optarg;
+                               options->port = pg_strdup(optarg);
                                break;
                        case 'P':
                                {
@@ -503,7 +503,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
                                pset.popt.topt.tableAttr = pg_strdup(optarg);
                                break;
                        case 'U':
-                               options->username = optarg;
+                               options->username = pg_strdup(optarg);
                                break;
                        case 'v':
                                {
index b8ac6759b489df57df38ad7d098a1f667321ea83..261b438edad15e5617a3daa34bb5ed145ccbb33b 100644 (file)
@@ -71,13 +71,13 @@ main(int argc, char *argv[])
                switch (c)
                {
                        case 'h':
-                               host = optarg;
+                               host = pg_strdup(optarg);
                                break;
                        case 'p':
-                               port = optarg;
+                               port = pg_strdup(optarg);
                                break;
                        case 'U':
-                               username = optarg;
+                               username = pg_strdup(optarg);
                                break;
                        case 'w':
                                prompt_password = TRI_NO;
@@ -92,19 +92,19 @@ main(int argc, char *argv[])
                                quiet = true;
                                break;
                        case 'd':
-                               dbname = optarg;
+                               dbname = pg_strdup(optarg);
                                break;
                        case 'a':
                                alldb = true;
                                break;
                        case 't':
-                               table = optarg;
+                               table = pg_strdup(optarg);
                                break;
                        case 'v':
                                verbose = true;
                                break;
                        case 2:
-                               maintenance_db = optarg;
+                               maintenance_db = pg_strdup(optarg);
                                break;
                        default:
                                fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
index 91b1a24fd3224c7e0fb6dd2c4f366e9955acba92..4df70cbfc6ab4afdcd86d6f244dd8c08d9e24cf2 100644 (file)
@@ -74,13 +74,13 @@ main(int argc, char *argv[])
                switch (c)
                {
                        case 'h':
-                               host = optarg;
+                               host = pg_strdup(optarg);
                                break;
                        case 'p':
-                               port = optarg;
+                               port = pg_strdup(optarg);
                                break;
                        case 'U':
-                               username = optarg;
+                               username = pg_strdup(optarg);
                                break;
                        case 'w':
                                prompt_password = TRI_NO;
@@ -92,28 +92,28 @@ main(int argc, char *argv[])
                                echo = true;
                                break;
                        case 'O':
-                               owner = optarg;
+                               owner = pg_strdup(optarg);
                                break;
                        case 'D':
-                               tablespace = optarg;
+                               tablespace = pg_strdup(optarg);
                                break;
                        case 'T':
-                               template = optarg;
+                               template = pg_strdup(optarg);
                                break;
                        case 'E':
-                               encoding = optarg;
+                               encoding = pg_strdup(optarg);
                                break;
                        case 1:
-                               lc_collate = optarg;
+                               lc_collate = pg_strdup(optarg);
                                break;
                        case 2:
-                               lc_ctype = optarg;
+                               lc_ctype = pg_strdup(optarg);
                                break;
                        case 'l':
-                               locale = optarg;
+                               locale = pg_strdup(optarg);
                                break;
                        case 3:
-                               maintenance_db = optarg;
+                               maintenance_db = pg_strdup(optarg);
                                break;
                        default:
                                fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
index 60066af377f4f83a17bca2a95fdbb3802c88815b..b85cf04e7a195fb3522bf3c4c2376306933c0008 100644 (file)
@@ -65,13 +65,13 @@ main(int argc, char *argv[])
                                listlangs = true;
                                break;
                        case 'h':
-                               host = optarg;
+                               host = pg_strdup(optarg);
                                break;
                        case 'p':
-                               port = optarg;
+                               port = pg_strdup(optarg);
                                break;
                        case 'U':
-                               username = optarg;
+                               username = pg_strdup(optarg);
                                break;
                        case 'w':
                                prompt_password = TRI_NO;
@@ -80,7 +80,7 @@ main(int argc, char *argv[])
                                prompt_password = TRI_YES;
                                break;
                        case 'd':
-                               dbname = optarg;
+                               dbname = pg_strdup(optarg);
                                break;
                        case 'e':
                                echo = true;
index db3b5d04d8a50c166ef1c50cc8f6e28801f6d037..d35121b8aa5cdf9831286c0f5de935c92cb91595 100644 (file)
@@ -89,13 +89,13 @@ main(int argc, char *argv[])
                switch (c)
                {
                        case 'h':
-                               host = optarg;
+                               host = pg_strdup(optarg);
                                break;
                        case 'p':
-                               port = optarg;
+                               port = pg_strdup(optarg);
                                break;
                        case 'U':
-                               username = optarg;
+                               username = pg_strdup(optarg);
                                break;
                        case 'w':
                                prompt_password = TRI_NO;
@@ -139,7 +139,7 @@ main(int argc, char *argv[])
                                login = TRI_NO;
                                break;
                        case 'c':
-                               conn_limit = optarg;
+                               conn_limit = pg_strdup(optarg);
                                break;
                        case 'P':
                                pwprompt = true;
index 583655de6aec89e1e071f8a6780aec3d00a886ce..5f978ccb8385024d38e3fb51732d2c6244bc8b6d 100644 (file)
@@ -64,13 +64,13 @@ main(int argc, char *argv[])
                switch (c)
                {
                        case 'h':
-                               host = optarg;
+                               host = pg_strdup(optarg);
                                break;
                        case 'p':
-                               port = optarg;
+                               port = pg_strdup(optarg);
                                break;
                        case 'U':
-                               username = optarg;
+                               username = pg_strdup(optarg);
                                break;
                        case 'w':
                                prompt_password = TRI_NO;
@@ -88,7 +88,7 @@ main(int argc, char *argv[])
                                /* this covers the long options */
                                break;
                        case 2:
-                               maintenance_db = optarg;
+                               maintenance_db = pg_strdup(optarg);
                                break;
                        default:
                                fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
index 4772dc514e3fa92cf280893e7a6642c79953c618..b9f42bbccd37a36efe3bd3fee3a5f7751a64f177 100644 (file)
@@ -64,13 +64,13 @@ main(int argc, char *argv[])
                                listlangs = true;
                                break;
                        case 'h':
-                               host = optarg;
+                               host = pg_strdup(optarg);
                                break;
                        case 'p':
-                               port = optarg;
+                               port = pg_strdup(optarg);
                                break;
                        case 'U':
-                               username = optarg;
+                               username = pg_strdup(optarg);
                                break;
                        case 'w':
                                prompt_password = TRI_NO;
@@ -79,7 +79,7 @@ main(int argc, char *argv[])
                                prompt_password = TRI_YES;
                                break;
                        case 'd':
-                               dbname = optarg;
+                               dbname = pg_strdup(optarg);
                                break;
                        case 'e':
                                echo = true;
index d0bf6ff497841157215b03d915fd87d5bb640b20..7c101014c16f136cad8b45c9f021d0fc1346944f 100644 (file)
@@ -62,13 +62,13 @@ main(int argc, char *argv[])
                switch (c)
                {
                        case 'h':
-                               host = optarg;
+                               host = pg_strdup(optarg);
                                break;
                        case 'p':
-                               port = optarg;
+                               port = pg_strdup(optarg);
                                break;
                        case 'U':
-                               username = optarg;
+                               username = pg_strdup(optarg);
                                break;
                        case 'w':
                                prompt_password = TRI_NO;
index d1e27bdb5f73b63efef9b0f1fed1a26b9f733f1e..f61dadaf55b0021075a46ff39f071c790a50067a 100644 (file)
@@ -78,13 +78,13 @@ main(int argc, char *argv[])
                switch (c)
                {
                        case 'h':
-                               host = optarg;
+                               host = pg_strdup(optarg);
                                break;
                        case 'p':
-                               port = optarg;
+                               port = pg_strdup(optarg);
                                break;
                        case 'U':
-                               username = optarg;
+                               username = pg_strdup(optarg);
                                break;
                        case 'w':
                                prompt_password = TRI_NO;
@@ -99,7 +99,7 @@ main(int argc, char *argv[])
                                quiet = true;
                                break;
                        case 'd':
-                               dbname = optarg;
+                               dbname = pg_strdup(optarg);
                                break;
                        case 'a':
                                alldb = true;
@@ -108,13 +108,13 @@ main(int argc, char *argv[])
                                syscatalog = true;
                                break;
                        case 't':
-                               table = optarg;
+                               table = pg_strdup(optarg);
                                break;
                        case 'i':
-                               index = optarg;
+                               index = pg_strdup(optarg);
                                break;
                        case 2:
-                               maintenance_db = optarg;
+                               maintenance_db = pg_strdup(optarg);
                                break;
                        default:
                                fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
index 0ac6ab4ed592d8737f169bedc76def22339e65cf..eb28ad4cc0f15b86f7230cc8ad6c7aee1fcca4c6 100644 (file)
@@ -82,13 +82,13 @@ main(int argc, char *argv[])
                switch (c)
                {
                        case 'h':
-                               host = optarg;
+                               host = pg_strdup(optarg);
                                break;
                        case 'p':
-                               port = optarg;
+                               port = pg_strdup(optarg);
                                break;
                        case 'U':
-                               username = optarg;
+                               username = pg_strdup(optarg);
                                break;
                        case 'w':
                                prompt_password = TRI_NO;
@@ -103,7 +103,7 @@ main(int argc, char *argv[])
                                quiet = true;
                                break;
                        case 'd':
-                               dbname = optarg;
+                               dbname = pg_strdup(optarg);
                                break;
                        case 'z':
                                and_analyze = true;
@@ -118,7 +118,7 @@ main(int argc, char *argv[])
                                alldb = true;
                                break;
                        case 't':
-                               table = optarg;
+                               table = pg_strdup(optarg);
                                break;
                        case 'f':
                                full = true;
@@ -127,7 +127,7 @@ main(int argc, char *argv[])
                                verbose = true;
                                break;
                        case 2:
-                               maintenance_db = optarg;
+                               maintenance_db = pg_strdup(optarg);
                                break;
                        default:
                                fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
index 7e7bae30a0b8ff8fb8c561c37564669273d6de1e..1b775a13e8f04afdebbf366ec969120ec6aaa475 100644 (file)
@@ -171,7 +171,7 @@ main(int argc, char *const argv[])
                                regression_mode = true;
                                break;
                        case 'o':
-                               output_filename = optarg;
+                               output_filename = strdup(optarg);
                                if (strcmp(output_filename, "-") == 0)
                                        yyout = stdout;
                                else
index 8a95d6ac3f7803237bb7f6c2941af574716a1576..0aa90ebfca1b25ad2100f4856ed635fe8aea9792 100644 (file)
@@ -505,7 +505,7 @@ main(int argc, char *argv[])
                                usage(stderr, EXIT_FAILURE);
                        case 'd':
                                if (directory == NULL)
-                                       directory = optarg;
+                                       directory = strdup(optarg);
                                else
                                {
                                        (void) fprintf(stderr,
@@ -516,7 +516,7 @@ main(int argc, char *argv[])
                                break;
                        case 'l':
                                if (lcltime == NULL)
-                                       lcltime = optarg;
+                                       lcltime = strdup(optarg);
                                else
                                {
                                        (void) fprintf(stderr,
@@ -527,7 +527,7 @@ main(int argc, char *argv[])
                                break;
                        case 'p':
                                if (psxrules == NULL)
-                                       psxrules = optarg;
+                                       psxrules = strdup(optarg);
                                else
                                {
                                        (void) fprintf(stderr,
@@ -538,7 +538,7 @@ main(int argc, char *argv[])
                                break;
                        case 'y':
                                if (yitcommand == NULL)
-                                       yitcommand = optarg;
+                                       yitcommand = strdup(optarg);
                                else
                                {
                                        (void) fprintf(stderr,
@@ -549,7 +549,7 @@ main(int argc, char *argv[])
                                break;
                        case 'L':
                                if (leapsec == NULL)
-                                       leapsec = optarg;
+                                       leapsec = strdup(optarg);
                                else
                                {
                                        (void) fprintf(stderr,