Commits

Anonymous committed 49ec613

In our source code, make a copy of getopt's 'optarg' string arguments,
rather than just storing a pointer.

Comments (0)

Files changed (20)

contrib/pg_archivecleanup/pg_archivecleanup.c

 				dryrun = true;
 				break;
 			case 'x':
-				additional_ext = optarg;		/* Extension to remove from
+				additional_ext = strdup(optarg);		/* Extension to remove from
 												 * xlogfile names */
 				break;
 			default:

contrib/pg_standby/pg_standby.c

 				}
 				break;
 			case 't':			/* Trigger file */
-				triggerPath = optarg;
+				triggerPath = strdup(optarg);
 				break;
 			case 'w':			/* Max wait time */
 				maxwaittime = atoi(optarg);

contrib/pgbench/pgbench.c

 				is_init_mode++;
 				break;
 			case 'h':
-				pghost = optarg;
+				pghost = pg_strdup(optarg);
 				break;
 			case 'n':
 				is_no_vacuum++;
 				do_vacuum_accounts++;
 				break;
 			case 'p':
-				pgport = optarg;
+				pgport = pg_strdup(optarg);
 				break;
 			case 'd':
 				debug++;
 				}
 				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;
 				/* 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);

src/backend/bootstrap/bootstrap.c

 				SetConfigOption("shared_buffers", optarg, PGC_POSTMASTER, PGC_S_ARGV);
 				break;
 			case 'D':
-				userDoption = optarg;
+				userDoption = strdup(optarg);
 				break;
 			case 'd':
 				{

src/backend/postmaster/postmaster.c

 				break;
 
 			case 'C':
-				output_config_variable = optarg;
+				output_config_variable = strdup(optarg);
 				break;
 
 			case 'D':
-				userDoption = optarg;
+				userDoption = strdup(optarg);
 				break;
 
 			case 'd':

src/bin/pg_dump/pg_dump.c

 				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':
 				break;
 
 			case 'p':			/* server port */
-				pgport = optarg;
+				pgport = pg_strdup(optarg);
 				break;
 
 			case 'R':
 				break;
 
 			case 'U':
-				username = optarg;
+				username = pg_strdup(optarg);
 				break;
 
 			case 'v':			/* verbose */
 				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 */

src/bin/pg_dump/pg_dumpall.c

 				break;
 
 			case 'f':
-				filename = optarg;
+				filename = pg_strdup(optarg);
 				appendPQExpBuffer(pgdumpopts, " -f ");
 				doShellQuoting(pgdumpopts, filename);
 				break;
 				break;
 
 			case 'h':
-				pghost = optarg;
+				pghost = pg_strdup(optarg);
 				appendPQExpBuffer(pgdumpopts, " -h ");
 				doShellQuoting(pgdumpopts, pghost);
 				break;
 				break;
 
 			case 'l':
-				pgdb = optarg;
+				pgdb = pg_strdup(optarg);
 				break;
 
 			case 'o':
 				break;
 
 			case 'p':
-				pgport = optarg;
+				pgport = pg_strdup(optarg);
 				appendPQExpBuffer(pgdumpopts, " -p ");
 				doShellQuoting(pgdumpopts, pgport);
 				break;
 				break;
 
 			case 'U':
-				pguser = optarg;
+				pguser = pg_strdup(optarg);
 				appendPQExpBuffer(pgdumpopts, " -U ");
 				doShellQuoting(pgdumpopts, pguser);
 				break;
 				break;
 
 			case 3:
-				use_role = optarg;
+				use_role = pg_strdup(optarg);
 				appendPQExpBuffer(pgdumpopts, " --role ");
 				doShellQuoting(pgdumpopts, use_role);
 				break;

src/bin/pg_dump/pg_restore.c

 				break;
 
 			case 'U':
-				opts->username = optarg;
+				opts->username = pg_strdup(optarg);
 				break;
 
 			case 'v':			/* verbose */
 				break;
 
 			case 2:				/* SET ROLE */
-				opts->use_role = optarg;
+				opts->use_role = pg_strdup(optarg);
 				break;
 
 			case 3:				/* section */

src/bin/psql/startup.c

 				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;
 					options->action = ACT_SINGLE_QUERY;
 				break;
 			case 'd':
-				options->dbname = optarg;
+				options->dbname = pg_strdup(optarg);
 				break;
 			case 'e':
 				SetVariable(pset.vars, "ECHO", "queries");
 				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;
 				options->action = ACT_LIST_DB;
 				break;
 			case 'L':
-				options->logfilename = optarg;
+				options->logfilename = pg_strdup(optarg);
 				break;
 			case 'n':
 				options->no_readline = true;
 				setQFout(optarg);
 				break;
 			case 'p':
-				options->port = optarg;
+				options->port = pg_strdup(optarg);
 				break;
 			case 'P':
 				{
 				pset.popt.topt.tableAttr = pg_strdup(optarg);
 				break;
 			case 'U':
-				options->username = optarg;
+				options->username = pg_strdup(optarg);
 				break;
 			case 'v':
 				{

src/bin/scripts/clusterdb.c

 		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;
 				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);

src/bin/scripts/createdb.c

 		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;
 				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);

src/bin/scripts/createlang.c

 				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;
 				prompt_password = TRI_YES;
 				break;
 			case 'd':
-				dbname = optarg;
+				dbname = pg_strdup(optarg);
 				break;
 			case 'e':
 				echo = true;

src/bin/scripts/createuser.c

 		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;
 				login = TRI_NO;
 				break;
 			case 'c':
-				conn_limit = optarg;
+				conn_limit = pg_strdup(optarg);
 				break;
 			case 'P':
 				pwprompt = true;

src/bin/scripts/dropdb.c

 		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;
 				/* 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);

src/bin/scripts/droplang.c

 				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;
 				prompt_password = TRI_YES;
 				break;
 			case 'd':
-				dbname = optarg;
+				dbname = pg_strdup(optarg);
 				break;
 			case 'e':
 				echo = true;

src/bin/scripts/dropuser.c

 		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;

src/bin/scripts/reindexdb.c

 		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;
 				quiet = true;
 				break;
 			case 'd':
-				dbname = optarg;
+				dbname = pg_strdup(optarg);
 				break;
 			case 'a':
 				alldb = true;
 				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);

src/bin/scripts/vacuumdb.c

 		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;
 				quiet = true;
 				break;
 			case 'd':
-				dbname = optarg;
+				dbname = pg_strdup(optarg);
 				break;
 			case 'z':
 				and_analyze = true;
 				alldb = true;
 				break;
 			case 't':
-				table = optarg;
+				table = pg_strdup(optarg);
 				break;
 			case 'f':
 				full = true;
 				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);

src/interfaces/ecpg/preproc/ecpg.c

 				regression_mode = true;
 				break;
 			case 'o':
-				output_filename = optarg;
+				output_filename = strdup(optarg);
 				if (strcmp(output_filename, "-") == 0)
 					yyout = stdout;
 				else

src/timezone/zic.c

 				usage(stderr, EXIT_FAILURE);
 			case 'd':
 				if (directory == NULL)
-					directory = optarg;
+					directory = strdup(optarg);
 				else
 				{
 					(void) fprintf(stderr,
 				break;
 			case 'l':
 				if (lcltime == NULL)
-					lcltime = optarg;
+					lcltime = strdup(optarg);
 				else
 				{
 					(void) fprintf(stderr,
 				break;
 			case 'p':
 				if (psxrules == NULL)
-					psxrules = optarg;
+					psxrules = strdup(optarg);
 				else
 				{
 					(void) fprintf(stderr,
 				break;
 			case 'y':
 				if (yitcommand == NULL)
-					yitcommand = optarg;
+					yitcommand = strdup(optarg);
 				else
 				{
 					(void) fprintf(stderr,
 				break;
 			case 'L':
 				if (leapsec == NULL)
-					leapsec = optarg;
+					leapsec = strdup(optarg);
 				else
 				{
 					(void) fprintf(stderr,