Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1e1d98d

Browse files
committed
Add upper bound for start_xid, start_mx_id and start_mx_offset
1 parent 1c49224 commit 1e1d98d

File tree

3 files changed

+50
-21
lines changed

3 files changed

+50
-21
lines changed

src/backend/bootstrap/bootstrap.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -250,28 +250,28 @@ AuxiliaryProcessMain(int argc, char *argv[])
250250
bootstrap_data_checksum_version = PG_DATA_CHECKSUM_VERSION;
251251
break;
252252
case 'm':
253-
if (sscanf(optarg, HEX_XID_FMT, &start_mx_id) != 1)
254-
{
255-
fprintf(stderr, "%s: invalid hex value of multixact-id\n", progname);
256-
exit(1);
257-
}
253+
if (sscanf(optarg, HEX_XID_FMT, &start_mx_id) != 1
254+
|| !StartMultiXactIdIsValid(start_mx_id))
255+
ereport(ERROR,
256+
(errcode(ERRCODE_SYNTAX_ERROR),
257+
errmsg("invalid start multixact id value")));
258258
break;
259259
case 'o':
260-
if (sscanf(optarg, XID_FMT, &start_mx_offset) != 1)
261-
{
262-
fprintf(stderr, "%s: invalid decimal value of multixact-offset\n", progname);
263-
exit(1);
264-
}
260+
if (sscanf(optarg, XID_FMT, &start_mx_offset) != 1
261+
|| !StartMultiXactOffsetIsValid(start_mx_offset))
262+
ereport(ERROR,
263+
(errcode(ERRCODE_SYNTAX_ERROR),
264+
errmsg("invalid start multixact offset value")));
265265
break;
266266
case 'r':
267267
strlcpy(OutputFileName, optarg, MAXPGPATH);
268268
break;
269269
case 'X':
270-
if (sscanf(optarg, HEX_XID_FMT, &start_xid) != 1)
271-
{
272-
fprintf(stderr, "%s: invalid hex value of xid\n", progname);
273-
exit(1);
274-
}
270+
if (sscanf(optarg, HEX_XID_FMT, &start_xid) != 1
271+
|| !StartTransactionIdIsValid(start_xid))
272+
ereport(ERROR,
273+
(errcode(ERRCODE_SYNTAX_ERROR),
274+
errmsg("invalid start xid value")));
275275
break;
276276
case 'x':
277277
MyAuxProcType = atoi(optarg);

src/bin/initdb/initdb.c

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2694,19 +2694,19 @@ usage(const char *progname)
26942694
printf(_(" -W, --pwprompt prompt for a password for the new superuser\n"));
26952695
printf(_(" -X, --xlogdir=XLOGDIR location for the transaction log directory\n"));
26962696
printf(_(" -x, --xid=START_XID specify start xid value in decimal format for new db instance to test 64-bit xids,\n"
2697-
" default value is 0\n"));
2697+
" default value is 0, max value is 2^62-1\n"));
26982698
printf(_("\nLess commonly used options:\n"));
26992699
printf(_(" -d, --debug generate lots of debugging output\n"));
27002700
printf(_(" -k, --data-checksums use data page checksums\n"));
27012701
printf(_(" -L DIRECTORY where to find the input files\n"));
27022702
printf(_(" -m, --multixact-id=START_MX_ID\n"
27032703
" specify start multixact id value in decimal format for new db instance\n"
2704-
" to test 64-bit xids, default value is 0\n"));
2704+
" to test 64-bit xids, default value is 0, max value is 2^62-1\n"));
27052705
printf(_(" -n, --noclean do not clean up after errors\n"));
27062706
printf(_(" -N, --nosync do not wait for changes to be written safely to disk\n"));
27072707
printf(_(" -o, --multixact-offset=START_MX_OFFSET\n"
27082708
" specify start multixact offset value in decimal format for new db instance\n"
2709-
" to test 64-bit xids, default value is 0\n"));
2709+
" to test 64-bit xids, default value is 0, max value is 2^62-1\n"));
27102710
printf(_(" -s, --show show internal settings\n"));
27112711
printf(_(" -S, --sync-only only sync data directory\n"));
27122712
printf(_("\nOther options:\n"));
@@ -3471,7 +3471,14 @@ main(int argc, char *argv[])
34713471
case 'm':
34723472
if (sscanf(optarg, XID_FMT, &start_mx_id) != 1)
34733473
{
3474-
fprintf(stderr, "%s: invalid decimal value of multixact-id\n", progname);
3474+
fprintf(stderr, "%s: invalid decimal START_MX_ID value\n",
3475+
progname);
3476+
exit(1);
3477+
}
3478+
if (!StartMultiXactIdIsValid(start_mx_id))
3479+
{
3480+
fprintf(stderr, "%s: out-of-range START_MX_ID value (the value must be less than 2^62)\n",
3481+
progname);
34753482
exit(1);
34763483
}
34773484
break;
@@ -3485,7 +3492,14 @@ main(int argc, char *argv[])
34853492
case 'o':
34863493
if (sscanf(optarg, XID_FMT, &start_mx_offset) != 1)
34873494
{
3488-
fprintf(stderr, "%s: invalid decimal value of multixact-offset\n", progname);
3495+
fprintf(stderr, "%s: invalid decimal START_MX_OFFSET value\n",
3496+
progname);
3497+
exit(1);
3498+
}
3499+
if (!StartMultiXactOffsetIsValid(start_mx_offset))
3500+
{
3501+
fprintf(stderr, "%s: out-of-range START_MX_OFFSET value (the value must be less than 2^62)\n",
3502+
progname);
34893503
exit(1);
34903504
}
34913505
break;
@@ -3537,7 +3551,14 @@ main(int argc, char *argv[])
35373551
case 'x':
35383552
if (sscanf(optarg, XID_FMT, &start_xid) != 1)
35393553
{
3540-
fprintf(stderr, "%s: invalid decimal value of xid\n", progname);
3554+
fprintf(stderr, "%s: invalid decimal START_XID value\n",
3555+
progname);
3556+
exit(1);
3557+
}
3558+
if (!StartTransactionIdIsValid(start_xid))
3559+
{
3560+
fprintf(stderr, "%s: out-of-range START_XID value (the value must be less than 2^62)\n",
3561+
progname);
35413562
exit(1);
35423563
}
35433564
break;

src/include/c.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,13 +390,17 @@ typedef double float8;
390390
typedef Oid regproc;
391391
typedef regproc RegProcedure;
392392

393+
#define MAX_START_XID UINT64CONST(0x3fffffffffffffff)
394+
393395
typedef uint64 TransactionId;
394396

395397
#define TransactionIdPrecedes(id1, id2) ((id1) < (id2))
396398
#define TransactionIdPrecedesOrEquals(id1, id2) ((id1) <= (id2))
397399
#define TransactionIdFollows(id1, id2) ((id1) > (id2))
398400
#define TransactionIdFollowsOrEquals(id1, id2) ((id1) >= (id2))
399401

402+
#define StartTransactionIdIsValid(start_xid) ((start_xid) <= MAX_START_XID)
403+
400404
typedef uint32 ShortTransactionId;
401405

402406
typedef uint64 LocalTransactionId;
@@ -417,8 +421,12 @@ typedef TransactionId MultiXactId;
417421
#define MultiXactIdFollows(id1, id2) ((id1) > (id2))
418422
#define MultiXactIdFollowsOrEquals(id1, id2) ((id1) >= (id2))
419423

424+
#define StartMultiXactIdIsValid(start_mx_id) ((start_mx_id) <= MAX_START_XID)
425+
420426
typedef uint64 MultiXactOffset;
421427

428+
#define StartMultiXactOffsetIsValid(start_mx_offset) ((start_mx_offset) <= MAX_START_XID)
429+
422430
typedef uint32 CommandId;
423431

424432
#define FirstCommandId ((CommandId) 0)

0 commit comments

Comments
 (0)