summaryrefslogtreecommitdiffstats
path: root/runtime/debug.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2010-03-15 09:29:54 +0100
committerRainer Gerhards <rgerhards@adiscon.com>2010-03-15 09:29:54 +0100
commita1127abbae67ac3a9c154b1914b15f1e16deca56 (patch)
treeb54c896fa3e4a879f819acd3506d4c225681a82d /runtime/debug.c
parent4f97db43dfbf78f08509a71a0924347d900707b8 (diff)
downloadrsyslog-a1127abbae67ac3a9c154b1914b15f1e16deca56.tar.gz
rsyslog-a1127abbae67ac3a9c154b1914b15f1e16deca56.tar.xz
rsyslog-a1127abbae67ac3a9c154b1914b15f1e16deca56.zip
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.
Diffstat (limited to 'runtime/debug.c')
-rw-r--r--runtime/debug.c9
1 files changed, 9 insertions, 0 deletions
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);
}