summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Momjian2012-10-12 17:35:40 +0000
committerBruce Momjian2012-10-12 17:35:43 +0000
commit49ec613201b2e9debdf9e9ad9a2ad7c6c8083729 (patch)
tree16626d363ecc7b021b2fda82bb27b811e2335c09
parenta29f7ed5544ef583747c0dcc3fc2afac1fb191ef (diff)
In our source code, make a copy of getopt's 'optarg' string arguments,
rather than just storing a pointer.
-rw-r--r--contrib/pg_archivecleanup/pg_archivecleanup.c2
-rw-r--r--contrib/pg_standby/pg_standby.c2
-rw-r--r--contrib/pgbench/pgbench.c12
-rw-r--r--src/backend/bootstrap/bootstrap.c2
-rw-r--r--src/backend/postmaster/postmaster.c4
-rw-r--r--src/bin/pg_dump/pg_dump.c16
-rw-r--r--src/bin/pg_dump/pg_dumpall.c12
-rw-r--r--src/bin/pg_dump/pg_restore.c4
-rw-r--r--src/bin/psql/startup.c14
-rw-r--r--src/bin/scripts/clusterdb.c12
-rw-r--r--src/bin/scripts/createdb.c22
-rw-r--r--src/bin/scripts/createlang.c8
-rw-r--r--src/bin/scripts/createuser.c8
-rw-r--r--src/bin/scripts/dropdb.c8
-rw-r--r--src/bin/scripts/droplang.c8
-rw-r--r--src/bin/scripts/dropuser.c6
-rw-r--r--src/bin/scripts/reindexdb.c14
-rw-r--r--src/bin/scripts/vacuumdb.c12
-rw-r--r--src/interfaces/ecpg/preproc/ecpg.c2
-rw-r--r--src/timezone/zic.c10
20 files changed, 89 insertions, 89 deletions
diff --git a/contrib/pg_archivecleanup/pg_archivecleanup.c b/contrib/pg_archivecleanup/pg_archivecleanup.c
index 8f77998de1..e97a11cb49 100644
--- a/contrib/pg_archivecleanup/pg_archivecleanup.c
+++ b/contrib/pg_archivecleanup/pg_archivecleanup.c
@@ -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:
diff --git a/contrib/pg_standby/pg_standby.c b/contrib/pg_standby/pg_standby.c
index 84941ede13..659bd50da7 100644
--- a/contrib/pg_standby/pg_standby.c
+++ b/contrib/pg_standby/pg_standby.c
@@ -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);
diff --git a/contrib/pgbench/pgbench.c b/contrib/pgbench/pgbench.c
index c399d59d25..5d48aeeae4 100644
--- a/contrib/pgbench/pgbench.c
+++ b/contrib/pgbench/pgbench.c
@@ -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);
diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c
index 34ddebbc0b..11086e2964 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -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':
{
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index e73caa8b29..dfe40492d2 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -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':
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 9920d96724..dd2019a1fb 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -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 */
diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c
index 10ce2223df..ca95bad1cc 100644
--- a/src/bin/pg_dump/pg_dumpall.c
+++ b/src/bin/pg_dump/pg_dumpall.c
@@ -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;
diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c
index f6c835be0d..49d799b953 100644
--- a/src/bin/pg_dump/pg_restore.c
+++ b/src/bin/pg_dump/pg_restore.c
@@ -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 */
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index 3fb12c9452..1fcc47fad3 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -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':
{
diff --git a/src/bin/scripts/clusterdb.c b/src/bin/scripts/clusterdb.c
index b8ac6759b4..261b438eda 100644
--- a/src/bin/scripts/clusterdb.c
+++ b/src/bin/scripts/clusterdb.c
@@ -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);
diff --git a/src/bin/scripts/createdb.c b/src/bin/scripts/createdb.c
index 91b1a24fd3..4df70cbfc6 100644
--- a/src/bin/scripts/createdb.c
+++ b/src/bin/scripts/createdb.c
@@ -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);
diff --git a/src/bin/scripts/createlang.c b/src/bin/scripts/createlang.c
index 60066af377..b85cf04e7a 100644
--- a/src/bin/scripts/createlang.c
+++ b/src/bin/scripts/createlang.c
@@ -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;
diff --git a/src/bin/scripts/createuser.c b/src/bin/scripts/createuser.c
index db3b5d04d8..d35121b8aa 100644
--- a/src/bin/scripts/createuser.c
+++ b/src/bin/scripts/createuser.c
@@ -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;
diff --git a/src/bin/scripts/dropdb.c b/src/bin/scripts/dropdb.c
index 583655de6a..5f978ccb83 100644
--- a/src/bin/scripts/dropdb.c
+++ b/src/bin/scripts/dropdb.c
@@ -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);
diff --git a/src/bin/scripts/droplang.c b/src/bin/scripts/droplang.c
index 4772dc514e..b9f42bbccd 100644
--- a/src/bin/scripts/droplang.c
+++ b/src/bin/scripts/droplang.c
@@ -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;
diff --git a/src/bin/scripts/dropuser.c b/src/bin/scripts/dropuser.c
index d0bf6ff497..7c101014c1 100644
--- a/src/bin/scripts/dropuser.c
+++ b/src/bin/scripts/dropuser.c
@@ -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;
diff --git a/src/bin/scripts/reindexdb.c b/src/bin/scripts/reindexdb.c
index d1e27bdb5f..f61dadaf55 100644
--- a/src/bin/scripts/reindexdb.c
+++ b/src/bin/scripts/reindexdb.c
@@ -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);
diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c
index 0ac6ab4ed5..eb28ad4cc0 100644
--- a/src/bin/scripts/vacuumdb.c
+++ b/src/bin/scripts/vacuumdb.c
@@ -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);
diff --git a/src/interfaces/ecpg/preproc/ecpg.c b/src/interfaces/ecpg/preproc/ecpg.c
index 7e7bae30a0..1b775a13e8 100644
--- a/src/interfaces/ecpg/preproc/ecpg.c
+++ b/src/interfaces/ecpg/preproc/ecpg.c
@@ -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
diff --git a/src/timezone/zic.c b/src/timezone/zic.c
index 8a95d6ac3f..0aa90ebfca 100644
--- a/src/timezone/zic.c
+++ b/src/timezone/zic.c
@@ -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,