Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

rather than just storing a pointer.
  • Loading branch information...
commit 49ec613201b2e9debdf9e9ad9a2ad7c6c8083729 1 parent a29f7ed
@bmomjian bmomjian authored
View
2  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:
View
2  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);
View
12 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);
View
2  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':
{
View
4 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':
View
16 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 */
View
12 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;
View
4 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 */
View
14 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':
{
View
12 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);
View
22 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);
View
8 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;
View
8 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;
View
8 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);
View
8 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;
View
6 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;
View
14 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);
View
12 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);
View
2  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
View
10 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,
Please sign in to comment.
Something went wrong with that request. Please try again.