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

Commitdde1a35

Browse files
committed
libpq_pipeline: Must strdup(optarg) to avoid crash
I forgot to strdup() when processing argv[]. Apparently many platformshide this mistake from users, but in those that don't you may get aprogram crash. Repair.Per buildfarm member drongo, which is the only one in all the buildfarmmanifesting a problem here.While at it, move "numrows" processing out of the line of special cases,and make it getopt's -r instead. (A similar thing could be done to'conninfo', but current use of the program doesn't warrant spending timeon that -- nowhere else we use conninfo in so simplistic a manner.)Discussion:https://postgr.es/m/20210401124850.GA19247@alvherre.pgsql
1 parentf82de5c commitdde1a35

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

‎src/test/modules/libpq_pipeline/libpq_pipeline.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ test_pipelined_insert(PGconn *conn, int n_rows)
725725
{
726726
snprintf(insert_param_0,MAXINTLEN,"%d",rows_to_send);
727727
snprintf(insert_param_1,MAXINT8LEN,"%lld",
728-
(long long)rows_to_send);
728+
(1L <<62)+ (long long)rows_to_send);
729729

730730
if (PQsendQueryPrepared(conn,"my_insert",
731731
2,insert_params,NULL,NULL,0)==1)
@@ -1227,9 +1227,10 @@ usage(const char *progname)
12271227
fprintf(stderr,"%s tests libpq's pipeline mode.\n\n",progname);
12281228
fprintf(stderr,"Usage:\n");
12291229
fprintf(stderr," %s [OPTION] tests\n",progname);
1230-
fprintf(stderr," %s [OPTION] TESTNAME [CONNINFO [NUMBER_OF_ROWS]\n",progname);
1230+
fprintf(stderr," %s [OPTION] TESTNAME [CONNINFO]\n",progname);
12311231
fprintf(stderr,"\nOptions:\n");
12321232
fprintf(stderr," -t TRACEFILE generate a libpq trace to TRACEFILE\n");
1233+
fprintf(stderr," -r NUMROWS use NUMROWS as the test size\n");
12331234
}
12341235

12351236
staticvoid
@@ -1256,19 +1257,29 @@ main(int argc, char **argv)
12561257
PGresult*res;
12571258
intc;
12581259

1259-
while ((c=getopt(argc,argv,"t:"))!=-1)
1260+
while ((c=getopt(argc,argv,"t:r:"))!=-1)
12601261
{
12611262
switch (c)
12621263
{
12631264
case't':/* trace file */
12641265
tracefile=pg_strdup(optarg);
12651266
break;
1267+
case'r':/* numrows */
1268+
errno=0;
1269+
numrows=strtol(optarg,NULL,10);
1270+
if (errno!=0||numrows <=0)
1271+
{
1272+
fprintf(stderr,"couldn't parse \"%s\" as a positive integer\n",
1273+
optarg);
1274+
exit(1);
1275+
}
1276+
break;
12661277
}
12671278
}
12681279

12691280
if (optind<argc)
12701281
{
1271-
testname=argv[optind];
1282+
testname=pg_strdup(argv[optind]);
12721283
optind++;
12731284
}
12741285
else
@@ -1285,18 +1296,7 @@ main(int argc, char **argv)
12851296

12861297
if (optind<argc)
12871298
{
1288-
conninfo=argv[optind];
1289-
optind++;
1290-
}
1291-
if (optind<argc)
1292-
{
1293-
errno=0;
1294-
numrows=strtol(argv[optind],NULL,10);
1295-
if (errno!=0||numrows <=0)
1296-
{
1297-
fprintf(stderr,"couldn't parse \"%s\" as a positive integer\n",argv[optind]);
1298-
exit(1);
1299-
}
1299+
conninfo=pg_strdup(argv[optind]);
13001300
optind++;
13011301
}
13021302

‎src/test/modules/libpq_pipeline/t/001_libpq_pipeline.pl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
formy$testname (@tests)
2424
{
25-
my@extraargs = ();
25+
my@extraargs = ('-r',$numrows);
2626
my$cmptrace =grep(/^$testname$/,
2727
qw(simple_pipeline multi_pipelines prepared singlerow
2828
pipeline_abort transaction disallowed_in_pipeline)) > 0;
@@ -38,8 +38,7 @@
3838
$node->command_ok(
3939
[
4040
'libpq_pipeline',@extraargs,
41-
$testname,$node->connstr('postgres'),
42-
$numrows
41+
$testname,$node->connstr('postgres')
4342
],
4443
"libpq_pipeline$testname");
4544

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp