Permalink
Browse files

In our source code, make a copy of getopt's 'optarg' string arguments,

rather than just storing a pointer.
  • Loading branch information...
1 parent a29f7ed commit 49ec613201b2e9debdf9e9ad9a2ad7c6c8083729 @bmomjian bmomjian committed Oct 12, 2012
@@ -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:
@@ -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);
View
@@ -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);
@@ -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':
{
@@ -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':
View
@@ -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 */
@@ -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;
@@ -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 */
View
@@ -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':
{
@@ -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);
View
@@ -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);
@@ -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;
Oops, something went wrong.

0 comments on commit 49ec613

Please sign in to comment.