aboutsummaryrefslogtreecommitdiff
path: root/src/backend/lib/stringinfo.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/lib/stringinfo.c')
-rw-r--r--src/backend/lib/stringinfo.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/backend/lib/stringinfo.c b/src/backend/lib/stringinfo.c
index b0854ddc43b..a35f30b933b 100644
--- a/src/backend/lib/stringinfo.c
+++ b/src/backend/lib/stringinfo.c
@@ -9,7 +9,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/lib/stringinfo.c,v 1.45 2007/03/03 19:32:54 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/lib/stringinfo.c,v 1.46 2007/05/28 16:43:24 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -234,14 +234,17 @@ enlargeStringInfo(StringInfo str, int needed)
int newlen;
/*
- * Guard against ridiculous "needed" values, which can occur if we're fed
- * bogus data. Without this, we can get an overflow or infinite loop in
- * the following.
+ * Guard against out-of-range "needed" values. Without this, we can get
+ * an overflow or infinite loop in the following.
*/
- if (needed < 0 ||
- ((Size) needed) >= (MaxAllocSize - (Size) str->len))
- elog(ERROR, "invalid string enlargement request size %d",
- needed);
+ if (needed < 0) /* should not happen */
+ elog(ERROR, "invalid string enlargement request size: %d", needed);
+ if (((Size) needed) >= (MaxAllocSize - (Size) str->len))
+ ereport(ERROR,
+ (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
+ errmsg("out of memory"),
+ errdetail("Cannot enlarge string buffer containing %d bytes by %d more bytes.",
+ str->len, needed)));
needed += str->len + 1; /* total space required now */