Skip to content
Snippets Groups Projects
Commit e7db8fa8 authored by Tom Lane's avatar Tom Lane
Browse files

Add Assert check to catch vsnprintf overrunning its buffer. (Seen to

occur on Solaris 7 in 64-bit mode, for one.)
parent aa39e9a8
No related branches found
No related tags found
No related merge requests found
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * 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,...) ...@@ -114,11 +114,22 @@ appendStringInfo(StringInfo str, const char *fmt,...)
avail = str->maxlen - str->len - 1; avail = str->maxlen - str->len - 1;
if (avail > 16) 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); va_start(args, fmt);
nprinted = vsnprintf(str->data + str->len, avail, nprinted = vsnprintf(str->data + str->len, avail,
fmt, args); fmt, args);
va_end(args); va_end(args);
Assert(str->data[str->maxlen-1] == '\0');
/* /*
* Note: some versions of vsnprintf return the number of chars * Note: some versions of vsnprintf return the number of chars
* actually stored, but at least one returns -1 on failure. Be * actually stored, but at least one returns -1 on failure. Be
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment