Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit49ec613

Browse files
committed
In our source code, make a copy of getopt's 'optarg' string arguments,
rather than just storing a pointer.
1 parenta29f7ed commit49ec613

File tree

20 files changed

+89
-89
lines changed

20 files changed

+89
-89
lines changed

‎contrib/pg_archivecleanup/pg_archivecleanup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ main(int argc, char **argv)
299299
dryrun= true;
300300
break;
301301
case'x':
302-
additional_ext=optarg;/* Extension to remove from
302+
additional_ext=strdup(optarg);/* Extension to remove from
303303
* xlogfile names */
304304
break;
305305
default:

‎contrib/pg_standby/pg_standby.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ main(int argc, char **argv)
643643
}
644644
break;
645645
case't':/* Trigger file */
646-
triggerPath=optarg;
646+
triggerPath=strdup(optarg);
647647
break;
648648
case'w':/* Max wait time */
649649
maxwaittime=atoi(optarg);

‎contrib/pgbench/pgbench.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,7 +1995,7 @@ main(int argc, char **argv)
19951995
is_init_mode++;
19961996
break;
19971997
case'h':
1998-
pghost=optarg;
1998+
pghost=pg_strdup(optarg);
19991999
break;
20002000
case'n':
20012001
is_no_vacuum++;
@@ -2004,7 +2004,7 @@ main(int argc, char **argv)
20042004
do_vacuum_accounts++;
20052005
break;
20062006
case'p':
2007-
pgport=optarg;
2007+
pgport=pg_strdup(optarg);
20082008
break;
20092009
case'd':
20102010
debug++;
@@ -2090,14 +2090,14 @@ main(int argc, char **argv)
20902090
}
20912091
break;
20922092
case'U':
2093-
login=optarg;
2093+
login=pg_strdup(optarg);
20942094
break;
20952095
case'l':
20962096
use_log= true;
20972097
break;
20982098
case'f':
20992099
ttype=3;
2100-
filename=optarg;
2100+
filename=pg_strdup(optarg);
21012101
if (process_file(filename)== false||*sql_files[num_files-1]==NULL)
21022102
exit(1);
21032103
break;
@@ -2143,10 +2143,10 @@ main(int argc, char **argv)
21432143
/* This covers long options which take no argument. */
21442144
break;
21452145
case2:/* tablespace */
2146-
tablespace=optarg;
2146+
tablespace=pg_strdup(optarg);
21472147
break;
21482148
case3:/* index-tablespace */
2149-
index_tablespace=optarg;
2149+
index_tablespace=pg_strdup(optarg);
21502150
break;
21512151
case4:
21522152
sample_rate=atof(optarg);

‎src/backend/bootstrap/bootstrap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ AuxiliaryProcessMain(int argc, char *argv[])
241241
SetConfigOption("shared_buffers",optarg,PGC_POSTMASTER,PGC_S_ARGV);
242242
break;
243243
case'D':
244-
userDoption=optarg;
244+
userDoption=strdup(optarg);
245245
break;
246246
case'd':
247247
{

‎src/backend/postmaster/postmaster.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,11 +570,11 @@ PostmasterMain(int argc, char *argv[])
570570
break;
571571

572572
case'C':
573-
output_config_variable=optarg;
573+
output_config_variable=strdup(optarg);
574574
break;
575575

576576
case'D':
577-
userDoption=optarg;
577+
userDoption=strdup(optarg);
578578
break;
579579

580580
case'd':

‎src/bin/pg_dump/pg_dump.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -409,19 +409,19 @@ main(int argc, char **argv)
409409
break;
410410

411411
case'E':/* Dump encoding */
412-
dumpencoding=optarg;
412+
dumpencoding=pg_strdup(optarg);
413413
break;
414414

415415
case'f':
416-
filename=optarg;
416+
filename=pg_strdup(optarg);
417417
break;
418418

419419
case'F':
420-
format=optarg;
420+
format=pg_strdup(optarg);
421421
break;
422422

423423
case'h':/* server host */
424-
pghost=optarg;
424+
pghost=pg_strdup(optarg);
425425
break;
426426

427427
case'i':
@@ -446,7 +446,7 @@ main(int argc, char **argv)
446446
break;
447447

448448
case'p':/* server port */
449-
pgport=optarg;
449+
pgport=pg_strdup(optarg);
450450
break;
451451

452452
case'R':
@@ -471,7 +471,7 @@ main(int argc, char **argv)
471471
break;
472472

473473
case'U':
474-
username=optarg;
474+
username=pg_strdup(optarg);
475475
break;
476476

477477
case'v':/* verbose */
@@ -499,11 +499,11 @@ main(int argc, char **argv)
499499
break;
500500

501501
case2:/* lock-wait-timeout */
502-
lockWaitTimeout=optarg;
502+
lockWaitTimeout=pg_strdup(optarg);
503503
break;
504504

505505
case3:/* SET ROLE */
506-
use_role=optarg;
506+
use_role=pg_strdup(optarg);
507507
break;
508508

509509
case4:/* exclude table(s) data */

‎src/bin/pg_dump/pg_dumpall.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ main(int argc, char *argv[])
200200
break;
201201

202202
case'f':
203-
filename=optarg;
203+
filename=pg_strdup(optarg);
204204
appendPQExpBuffer(pgdumpopts," -f ");
205205
doShellQuoting(pgdumpopts,filename);
206206
break;
@@ -210,7 +210,7 @@ main(int argc, char *argv[])
210210
break;
211211

212212
case'h':
213-
pghost=optarg;
213+
pghost=pg_strdup(optarg);
214214
appendPQExpBuffer(pgdumpopts," -h ");
215215
doShellQuoting(pgdumpopts,pghost);
216216
break;
@@ -220,7 +220,7 @@ main(int argc, char *argv[])
220220
break;
221221

222222
case'l':
223-
pgdb=optarg;
223+
pgdb=pg_strdup(optarg);
224224
break;
225225

226226
case'o':
@@ -232,7 +232,7 @@ main(int argc, char *argv[])
232232
break;
233233

234234
case'p':
235-
pgport=optarg;
235+
pgport=pg_strdup(optarg);
236236
appendPQExpBuffer(pgdumpopts," -p ");
237237
doShellQuoting(pgdumpopts,pgport);
238238
break;
@@ -255,7 +255,7 @@ main(int argc, char *argv[])
255255
break;
256256

257257
case'U':
258-
pguser=optarg;
258+
pguser=pg_strdup(optarg);
259259
appendPQExpBuffer(pgdumpopts," -U ");
260260
doShellQuoting(pgdumpopts,pguser);
261261
break;
@@ -289,7 +289,7 @@ main(int argc, char *argv[])
289289
break;
290290

291291
case3:
292-
use_role=optarg;
292+
use_role=pg_strdup(optarg);
293293
appendPQExpBuffer(pgdumpopts," --role ");
294294
doShellQuoting(pgdumpopts,use_role);
295295
break;

‎src/bin/pg_dump/pg_restore.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ main(int argc, char **argv)
238238
break;
239239

240240
case'U':
241-
opts->username=optarg;
241+
opts->username=pg_strdup(optarg);
242242
break;
243243

244244
case'v':/* verbose */
@@ -270,7 +270,7 @@ main(int argc, char **argv)
270270
break;
271271

272272
case2:/* SET ROLE */
273-
opts->use_role=optarg;
273+
opts->use_role=pg_strdup(optarg);
274274
break;
275275

276276
case3:/* section */

‎src/bin/psql/startup.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
411411
pset.popt.topt.format=PRINT_UNALIGNED;
412412
break;
413413
case'c':
414-
options->action_string=optarg;
414+
options->action_string=pg_strdup(optarg);
415415
if (optarg[0]=='\\')
416416
{
417417
options->action=ACT_SINGLE_SLASH;
@@ -421,7 +421,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
421421
options->action=ACT_SINGLE_QUERY;
422422
break;
423423
case'd':
424-
options->dbname=optarg;
424+
options->dbname=pg_strdup(optarg);
425425
break;
426426
case'e':
427427
SetVariable(pset.vars,"ECHO","queries");
@@ -431,14 +431,14 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
431431
break;
432432
case'f':
433433
options->action=ACT_FILE;
434-
options->action_string=optarg;
434+
options->action_string=pg_strdup(optarg);
435435
break;
436436
case'F':
437437
pset.popt.topt.fieldSep.separator=pg_strdup(optarg);
438438
pset.popt.topt.fieldSep.separator_zero= false;
439439
break;
440440
case'h':
441-
options->host=optarg;
441+
options->host=pg_strdup(optarg);
442442
break;
443443
case'H':
444444
pset.popt.topt.format=PRINT_HTML;
@@ -447,7 +447,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
447447
options->action=ACT_LIST_DB;
448448
break;
449449
case'L':
450-
options->logfilename=optarg;
450+
options->logfilename=pg_strdup(optarg);
451451
break;
452452
case'n':
453453
options->no_readline= true;
@@ -456,7 +456,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
456456
setQFout(optarg);
457457
break;
458458
case'p':
459-
options->port=optarg;
459+
options->port=pg_strdup(optarg);
460460
break;
461461
case'P':
462462
{
@@ -503,7 +503,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
503503
pset.popt.topt.tableAttr=pg_strdup(optarg);
504504
break;
505505
case'U':
506-
options->username=optarg;
506+
options->username=pg_strdup(optarg);
507507
break;
508508
case'v':
509509
{

‎src/bin/scripts/clusterdb.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ main(int argc, char *argv[])
7171
switch (c)
7272
{
7373
case'h':
74-
host=optarg;
74+
host=pg_strdup(optarg);
7575
break;
7676
case'p':
77-
port=optarg;
77+
port=pg_strdup(optarg);
7878
break;
7979
case'U':
80-
username=optarg;
80+
username=pg_strdup(optarg);
8181
break;
8282
case'w':
8383
prompt_password=TRI_NO;
@@ -92,19 +92,19 @@ main(int argc, char *argv[])
9292
quiet= true;
9393
break;
9494
case'd':
95-
dbname=optarg;
95+
dbname=pg_strdup(optarg);
9696
break;
9797
case'a':
9898
alldb= true;
9999
break;
100100
case't':
101-
table=optarg;
101+
table=pg_strdup(optarg);
102102
break;
103103
case'v':
104104
verbose= true;
105105
break;
106106
case2:
107-
maintenance_db=optarg;
107+
maintenance_db=pg_strdup(optarg);
108108
break;
109109
default:
110110
fprintf(stderr,_("Try \"%s --help\" for more information.\n"),progname);

‎src/bin/scripts/createdb.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ main(int argc, char *argv[])
7474
switch (c)
7575
{
7676
case'h':
77-
host=optarg;
77+
host=pg_strdup(optarg);
7878
break;
7979
case'p':
80-
port=optarg;
80+
port=pg_strdup(optarg);
8181
break;
8282
case'U':
83-
username=optarg;
83+
username=pg_strdup(optarg);
8484
break;
8585
case'w':
8686
prompt_password=TRI_NO;
@@ -92,28 +92,28 @@ main(int argc, char *argv[])
9292
echo= true;
9393
break;
9494
case'O':
95-
owner=optarg;
95+
owner=pg_strdup(optarg);
9696
break;
9797
case'D':
98-
tablespace=optarg;
98+
tablespace=pg_strdup(optarg);
9999
break;
100100
case'T':
101-
template=optarg;
101+
template=pg_strdup(optarg);
102102
break;
103103
case'E':
104-
encoding=optarg;
104+
encoding=pg_strdup(optarg);
105105
break;
106106
case1:
107-
lc_collate=optarg;
107+
lc_collate=pg_strdup(optarg);
108108
break;
109109
case2:
110-
lc_ctype=optarg;
110+
lc_ctype=pg_strdup(optarg);
111111
break;
112112
case'l':
113-
locale=optarg;
113+
locale=pg_strdup(optarg);
114114
break;
115115
case3:
116-
maintenance_db=optarg;
116+
maintenance_db=pg_strdup(optarg);
117117
break;
118118
default:
119119
fprintf(stderr,_("Try \"%s --help\" for more information.\n"),progname);

‎src/bin/scripts/createlang.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ main(int argc, char *argv[])
6565
listlangs= true;
6666
break;
6767
case'h':
68-
host=optarg;
68+
host=pg_strdup(optarg);
6969
break;
7070
case'p':
71-
port=optarg;
71+
port=pg_strdup(optarg);
7272
break;
7373
case'U':
74-
username=optarg;
74+
username=pg_strdup(optarg);
7575
break;
7676
case'w':
7777
prompt_password=TRI_NO;
@@ -80,7 +80,7 @@ main(int argc, char *argv[])
8080
prompt_password=TRI_YES;
8181
break;
8282
case'd':
83-
dbname=optarg;
83+
dbname=pg_strdup(optarg);
8484
break;
8585
case'e':
8686
echo= true;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp