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
This commit is contained in:
Robert Haas 2013-12-02 10:40:33 -05:00
parent 3e3520cf7a
commit 9d140f7be2

View File

@ -397,12 +397,13 @@ void
errfinish(int dummy,...) errfinish(int dummy,...)
{ {
ErrorData *edata = &errordata[errordata_stack_depth]; ErrorData *edata = &errordata[errordata_stack_depth];
int elevel = edata->elevel; int elevel;
MemoryContext oldcontext; MemoryContext oldcontext;
ErrorContextCallback *econtext; ErrorContextCallback *econtext;
recursion_depth++; recursion_depth++;
CHECK_STACK_DEPTH(); CHECK_STACK_DEPTH();
elevel = edata->elevel;
/* /*
* Do processing in ErrorContext, which we hope has enough reserved space * Do processing in ErrorContext, which we hope has enough reserved space