[PATCH] avoid buffer underflow in errfinish() - Mailing list pgsql-hackers

From Xi Wang
Subject [PATCH] avoid buffer underflow in errfinish()
Date
Msg-id 1364078281-11998-1-git-send-email-xi.wang@gmail.com
Whole thread Raw
Responses Re: [PATCH] avoid buffer underflow in errfinish()
Re: [PATCH] avoid buffer underflow in errfinish()
List pgsql-hackers
CHECK_STACK_DEPTH checks if errordata_stack_depth is negative.
Move the dereference of &errordata[errordata_stack_depth] after
the check to avoid out-of-bounds read.
---src/backend/utils/error/elog.c |    4 +++-1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 3a211bf..47a0a8b 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -393,13 +393,15 @@ voiderrfinish(int dummy,...){    ErrorData  *edata = &errordata[errordata_stack_depth];
-    int            elevel = edata->elevel;
+    int            elevel;    MemoryContext oldcontext;    ErrorContextCallback *econtext;    recursion_depth++;
CHECK_STACK_DEPTH();
+    elevel = edata->elevel;
+    /*     * Do processing in ErrorContext, which we hope has enough reserved space     * to report an error.
-- 
1.7.10.4




pgsql-hackers by date:

Previous
From: Nicholas White
Date:
Subject: Re: Request for Patch Feedback: Lag & Lead Window Functions Can Ignore Nulls
Next
From: Xi Wang
Date:
Subject: Re: [PATCH] avoid buffer underflow in errfinish()