[PATCH] avoid buffer underflow in errfinish()

From: Xi Wang <xi(dot)wang(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Xi Wang <xi(dot)wang(at)gmail(dot)com>
Subject: [PATCH] avoid buffer underflow in errfinish()
Date: 2013-03-23 22:38:01
Message-ID: 1364078281-11998-1-git-send-email-xi.wang@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 @@ void
errfinish(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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Xi Wang 2013-03-23 22:45:14 Re: [PATCH] avoid buffer underflow in errfinish()
Previous Message Nicholas White 2013-03-23 22:25:02 Re: Request for Patch Feedback: Lag & Lead Window Functions Can Ignore Nulls