diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2002-03-04 18:34:02 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2002-03-04 18:34:02 +0000 |
commit | e7db8fa80e58d43531469547e0f0ac1da77d3a8c (patch) | |
tree | a7a84d74cf1e514813442aa3f9d031dcd6f34f94 /src/backend/lib/stringinfo.c | |
parent | aa39e9a80c333f4dd2123cba861201abac59c671 (diff) | |
download | postgresql-e7db8fa80e58d43531469547e0f0ac1da77d3a8c.tar.gz postgresql-e7db8fa80e58d43531469547e0f0ac1da77d3a8c.zip |
Add Assert check to catch vsnprintf overrunning its buffer. (Seen to
occur on Solaris 7 in 64-bit mode, for one.)
Diffstat (limited to 'src/backend/lib/stringinfo.c')
-rw-r--r-- | src/backend/lib/stringinfo.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/backend/lib/stringinfo.c b/src/backend/lib/stringinfo.c index 1745f0f9ca1..544ae1b3a20 100644 --- a/src/backend/lib/stringinfo.c +++ b/src/backend/lib/stringinfo.c @@ -9,7 +9,7 @@ * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: stringinfo.c,v 1.29 2001/10/25 05:49:29 momjian Exp $ + * $Id: stringinfo.c,v 1.30 2002/03/04 18:34:02 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -114,11 +114,22 @@ appendStringInfo(StringInfo str, const char *fmt,...) avail = str->maxlen - str->len - 1; if (avail > 16) { + /* + * Assert check here is to catch buggy vsnprintf that overruns + * the specified buffer length. Solaris 7 in 64-bit mode is + * an example of a platform with such a bug. + */ +#ifdef USE_ASSERT_CHECKING + str->data[str->maxlen-1] = '\0'; +#endif + va_start(args, fmt); nprinted = vsnprintf(str->data + str->len, avail, fmt, args); va_end(args); + Assert(str->data[str->maxlen-1] == '\0'); + /* * Note: some versions of vsnprintf return the number of chars * actually stored, but at least one returns -1 on failure. Be |