Skip to content

Commit 9d140f7

Browse files
committed
Avoid out-of-bounds read in errfinish if error_stack_depth < 0.
If errordata_stack_depth < 0, we won't find that out and correct the problem until CHECK_STACK_DEPTH() is invoked. In the meantime, elevel will be set based on an invalid read. This is probably harmless in practice, but it seems cleaner this way. Xi Wang
1 parent 3e3520c commit 9d140f7

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/backend/utils/error/elog.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,12 +397,13 @@ void
397397
errfinish(int dummy,...)
398398
{
399399
ErrorData *edata = &errordata[errordata_stack_depth];
400-
int elevel = edata->elevel;
400+
int elevel;
401401
MemoryContext oldcontext;
402402
ErrorContextCallback *econtext;
403403

404404
recursion_depth++;
405405
CHECK_STACK_DEPTH();
406+
elevel = edata->elevel;
406407

407408
/*
408409
* Do processing in ErrorContext, which we hope has enough reserved space

0 commit comments

Comments
 (0)