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

Commitcf34fdb

Browse files
committed
Make AllocSetContextCreate throw an error for bad context-size parameters.
The previous behavior was to silently change them to something valid.That obscured the bugs fixed in commitea268cd, and generally seemsless useful than complaining. Unlike the previous commit, though,we'll do this in HEAD only --- it's a bit too late to be possiblybreaking third-party code in 9.6.Discussion: <CA+TgmobNcELVd3QmLD3tx=w7+CokRQiC4_U0txjz=WHpfdkU=w@mail.gmail.com>
1 parent4934062 commitcf34fdb

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

‎src/backend/utils/mmgr/aset.c

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -445,25 +445,34 @@ AllocSetContextCreate(MemoryContext parent,
445445
{
446446
AllocSetset;
447447

448+
/*
449+
* First, validate allocation parameters. (If we're going to throw an
450+
* error, we should do so before the context is created, not after.) We
451+
* somewhat arbitrarily enforce a minimum 1K block size.
452+
*/
453+
if (initBlockSize!=MAXALIGN(initBlockSize)||
454+
initBlockSize<1024)
455+
elog(ERROR,"invalid initBlockSize for memory context: %zu",
456+
initBlockSize);
457+
if (maxBlockSize!=MAXALIGN(maxBlockSize)||
458+
maxBlockSize<initBlockSize||
459+
!AllocHugeSizeIsValid(maxBlockSize))/* must be safe to double */
460+
elog(ERROR,"invalid maxBlockSize for memory context: %zu",
461+
maxBlockSize);
462+
if (minContextSize!=0&&
463+
(minContextSize!=MAXALIGN(minContextSize)||
464+
minContextSize <=ALLOC_BLOCKHDRSZ+ALLOC_CHUNKHDRSZ))
465+
elog(ERROR,"invalid minContextSize for memory context: %zu",
466+
minContextSize);
467+
448468
/* Do the type-independent part of context creation */
449469
set= (AllocSet)MemoryContextCreate(T_AllocSetContext,
450470
sizeof(AllocSetContext),
451471
&AllocSetMethods,
452472
parent,
453473
name);
454474

455-
/*
456-
* Make sure alloc parameters are reasonable, and save them.
457-
*
458-
* We somewhat arbitrarily enforce a minimum 1K block size.
459-
*/
460-
initBlockSize=MAXALIGN(initBlockSize);
461-
if (initBlockSize<1024)
462-
initBlockSize=1024;
463-
maxBlockSize=MAXALIGN(maxBlockSize);
464-
if (maxBlockSize<initBlockSize)
465-
maxBlockSize=initBlockSize;
466-
Assert(AllocHugeSizeIsValid(maxBlockSize));/* must be safe to double */
475+
/* Save allocation parameters */
467476
set->initBlockSize=initBlockSize;
468477
set->maxBlockSize=maxBlockSize;
469478
set->nextBlockSize=initBlockSize;
@@ -495,9 +504,9 @@ AllocSetContextCreate(MemoryContext parent,
495504
/*
496505
* Grab always-allocated space, if requested
497506
*/
498-
if (minContextSize>ALLOC_BLOCKHDRSZ+ALLOC_CHUNKHDRSZ)
507+
if (minContextSize>0)
499508
{
500-
Sizeblksize=MAXALIGN(minContextSize);
509+
Sizeblksize=minContextSize;
501510
AllocBlockblock;
502511

503512
block= (AllocBlock)malloc(blksize);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp