Blame SOURCES/rsyslog-8.24.0-rhbz1582517-buffer-overflow-memcpy-in-parser.patch

f656cf
From cc3098b63174b8aa875d1f2e9c6ea94407b211b8 Mon Sep 17 00:00:00 2001
f656cf
From: Rainer Gerhards <rgerhards@adiscon.com>
f656cf
Date: Thu, 16 Feb 2017 19:02:36 +0100
f656cf
Subject: [PATCH 04/11] Bug 1582517 - rsyslog: Buffer overflow in memcpy() in parser.c
f656cf
f656cf
core: fix potential misadressing in parser message sanitizer
f656cf
f656cf
misadressing could happen when an oversize message made it to the
f656cf
sanitizer AND contained a control character in the oversize part
f656cf
of the message. Note that it is an error in itself that such an
f656cf
oversize message enters the system, but we harden the sanitizer
f656cf
to handle this gracefully (it will truncate the message).
f656cf
f656cf
Note that truncation may still - as previously - happen if the
f656cf
number of escape characters makes the string grow above the max
f656cf
message size.
f656cf
f656cf
(cherry picked from commit 20f8237870eb5e971fa068e4dd4d296f1dbef329)
f656cf
---
f656cf
 runtime/parser.c | 8 +++++++-
f656cf
 1 file changed, 7 insertions(+), 1 deletion(-)
f656cf
f656cf
diff --git a/runtime/parser.c b/runtime/parser.c
f656cf
index 0574d982a..9645baa40 100644
f656cf
--- a/runtime/parser.c
f656cf
+++ b/runtime/parser.c
f656cf
@@ -464,9 +464,15 @@ SanitizeMsg(smsg_t *pMsg)
f656cf
 	if(maxDest < sizeof(szSanBuf))
f656cf
 		pDst = szSanBuf;
f656cf
 	else 
f656cf
-		CHKmalloc(pDst = MALLOC(iMaxLine + 1));
f656cf
+		CHKmalloc(pDst = MALLOC(maxDest + 1));
f656cf
 	if(iSrc > 0) {
f656cf
 		iSrc--; /* go back to where everything is OK */
f656cf
+		if(iSrc > maxDest) {
f656cf
+			DBGPRINTF("parser.Sanitize: have oversize index %zd, "
f656cf
+				"max %zd - corrected, but should not happen\n",
f656cf
+				iSrc, maxDest);
f656cf
+			iSrc = maxDest;
f656cf
+		}
f656cf
 		memcpy(pDst, pszMsg, iSrc); /* fast copy known good */
f656cf
 	}
f656cf
 	iDst = iSrc;
f656cf
-- 
f656cf
2.14.4
f656cf