From a1127abbae67ac3a9c154b1914b15f1e16deca56 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Mon, 15 Mar 2010 09:29:54 +0100 Subject: bugfix(minor): handling of extremely large strings in dbgprintf() fixed Previously, it could lead to garbagge output and, in extreme cases, also to segfaults. Note: this was a problem only when debug output was actually enabled, so it caused no problem in production use. --- ChangeLog | 4 ++++ runtime/debug.c | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/ChangeLog b/ChangeLog index 7fe59dd9..4a57639e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -20,6 +20,10 @@ Version 4.6.2 [v4-stable] (rgerhards), 2010-03-?? in proper retries. - bugfix: $omfileFlushOnTXEnd was turned on when set to off and vice versa due to an invalid check +- bugfix(minor): handling of extremely large strings in dbgprintf() fixed + Previously, it could lead to garbagge output and, in extreme cases, also + to segfaults. Note: this was a problem only when debug output was + actually enabled, so it caused no problem in production use. --------------------------------------------------------------------------- Version 4.6.1 [v4-stable] (rgerhards), 2010-03-04 - re-enabled old pipe output (using new module ompipe, built-in) after diff --git a/runtime/debug.c b/runtime/debug.c index 4504aaad..bc581a5d 100644 --- a/runtime/debug.c +++ b/runtime/debug.c @@ -961,6 +961,15 @@ dbgprintf(char *fmt, ...) va_start(ap, fmt); lenWriteBuf = vsnprintf(pszWriteBuf, sizeof(pszWriteBuf), fmt, ap); va_end(ap); + if(lenWriteBuf >= sizeof(pszWriteBuf)) { + /* prevent buffer overrruns and garbagge display */ + pszWriteBuf[sizeof(pszWriteBuf) - 5] = '.'; + pszWriteBuf[sizeof(pszWriteBuf) - 4] = '.'; + pszWriteBuf[sizeof(pszWriteBuf) - 3] = '.'; + pszWriteBuf[sizeof(pszWriteBuf) - 2] = '\n'; + pszWriteBuf[sizeof(pszWriteBuf) - 1] = '\0'; + lenWriteBuf = sizeof(pszWriteBuf); + } dbgprint(NULL, pszWriteBuf, lenWriteBuf); } -- cgit v1.2.3