Blame SOURCES/rsyslog-8.37.0-rhbz1677037-short-offMsg-overrun-crash.patch

c16178
From 1255a67fdec2fc44cd49b6ea8c463f4319910812 Mon Sep 17 00:00:00 2001
c16178
From: Jiri Vymazal <jvymazal@redhat.com>
c16178
Date: Wed, 27 Feb 2019 11:57:49 +0100
c16178
Subject: [PATCH] Enlarged msg offset types for bigger structured messages
c16178
c16178
using a large enough (dozens of kBs) structured message
c16178
it is possible to overflow the signed short type which leads
c16178
to rsyslog crash.
c16178
---
c16178
 runtime/msg.c | 12 ++++++------
c16178
 runtime/msg.h |  8 ++++----
c16178
 2 files changed, 10 insertions(+), 10 deletions(-)
c16178
c16178
diff --git a/runtime/msg.c b/runtime/msg.c
c16178
index b82c38b9ee..96306bbeab 100644
c16178
--- a/runtime/msg.c
c16178
+++ b/runtime/msg.c
c16178
@@ -839,7 +839,7 @@ msgBaseConstruct(smsg_t **ppThis)
c16178
 	pM->iFacility = LOG_INVLD;
c16178
 	pM->iLenPROGNAME = -1;
c16178
 	pM->offAfterPRI = 0;
c16178
-	pM->offMSG = -1;
c16178
+	pM->offMSG = 0;
c16178
 	pM->iProtocolVersion = 0;
c16178
 	pM->msgFlags = 0;
c16178
 	pM->iLenRawMsg = 0;
c16178
@@ -2167,7 +2167,7 @@ MsgSetFlowControlType(smsg_t * const pMsg, flowControl_t eFlowCtl)
c16178
  * rgerhards, 2009-06-16
c16178
  */
c16178
 rsRetVal
c16178
-MsgSetAfterPRIOffs(smsg_t * const pMsg, short offs)
c16178
+MsgSetAfterPRIOffs(smsg_t * const pMsg, uint32_t offs)
c16178
 {
c16178
 	assert(pMsg != NULL);
c16178
 	pMsg->offAfterPRI = offs;
c16178
@@ -2819,12 +2819,12 @@ void MsgSetHOSTNAME(smsg_t *pThis, const uchar* pszHOSTNAME, const int lenHOSTNA
c16178
  * (exactly by one). This can happen if we have a message that does not
c16178
  * contain any MSG part.
c16178
  */
c16178
-void MsgSetMSGoffs(smsg_t * const pMsg, short offs)
c16178
+void MsgSetMSGoffs(smsg_t * const pMsg, uint32_t offs)
c16178
 {
c16178
 	ISOBJ_TYPE_assert(pMsg, msg);
c16178
 	pMsg->offMSG = offs;
c16178
-	if(offs > pMsg->iLenRawMsg) {
c16178
-		assert(offs - 1 == pMsg->iLenRawMsg);
c16178
+	if(offs > (uint32_t)pMsg->iLenRawMsg) {
c16178
+		assert((int)offs - 1 == pMsg->iLenRawMsg);
c16178
 		pMsg->iLenMSG = 0;
c16178
 	} else {
c16178
 		pMsg->iLenMSG = pMsg->iLenRawMsg - offs;
c16178
@@ -2920,7 +2920,7 @@ MsgSetRawMsg(smsg_t *const pThis, const char*const pszRawMsg, const size_t lenMs
c16178
 	memcpy(pThis->pszRawMsg, pszRawMsg, pThis->iLenRawMsg);
c16178
 	pThis->pszRawMsg[pThis->iLenRawMsg] = '\0'; /* this also works with truncation! */
c16178
 	/* correct other information */
c16178
-	if(pThis->iLenRawMsg > pThis->offMSG)
c16178
+	if((uint32_t)pThis->iLenRawMsg > pThis->offMSG)
c16178
 		pThis->iLenMSG += deltaSize;
c16178
 	else
c16178
 		pThis->iLenMSG = 0;
c16178
diff --git a/runtime/msg.h b/runtime/msg.h
c16178
index 74439275b1..722cca6e8a 100644
c16178
--- a/runtime/msg.h
c16178
+++ b/runtime/msg.h
c16178
@@ -67,8 +67,8 @@ struct msg {
c16178
 	sbool	bParseSuccess;	/* set to reflect state of last executed higher level parser */
c16178
 	unsigned short	iSeverity;/* the severity  */
c16178
 	unsigned short	iFacility;/* Facility code */
c16178
-	short	offAfterPRI;	/* offset, at which raw message WITHOUT PRI part starts in pszRawMsg */
c16178
-	short	offMSG;		/* offset at which the MSG part starts in pszRawMsg */
c16178
+	uint32_t offAfterPRI;	/* offset, at which raw message WITHOUT PRI part starts in pszRawMsg */
c16178
+	uint32_t offMSG;		/* offset at which the MSG part starts in pszRawMsg */
c16178
 	short	iProtocolVersion;/* protocol version of message received 0 - legacy, 1 syslog-protocol) */
c16178
 	int	msgFlags;	/* flags associated with this message */
c16178
 	int	iLenRawMsg;	/* length of raw message */
c16178
@@ -194,8 +194,8 @@ void MsgSetRcvFromStr(smsg_t *const pMsg, const uchar* pszRcvFrom, const int, pr
c16178
 rsRetVal MsgSetRcvFromIP(smsg_t *pMsg, prop_t*);
c16178
 rsRetVal MsgSetRcvFromIPStr(smsg_t *const pThis, const uchar *psz, const int len, prop_t **ppProp);
c16178
 void MsgSetHOSTNAME(smsg_t *pMsg, const uchar* pszHOSTNAME, const int lenHOSTNAME);
c16178
-rsRetVal MsgSetAfterPRIOffs(smsg_t *pMsg, short offs);
c16178
-void MsgSetMSGoffs(smsg_t *pMsg, short offs);
c16178
+rsRetVal MsgSetAfterPRIOffs(smsg_t *pMsg, uint32_t offs);
c16178
+void MsgSetMSGoffs(smsg_t *pMsg, uint32_t offs);
c16178
 void MsgSetRawMsgWOSize(smsg_t *pMsg, char* pszRawMsg);
c16178
 void ATTR_NONNULL() MsgSetRawMsg(smsg_t *const pThis, const char*const pszRawMsg, const size_t lenMsg);
c16178
 rsRetVal MsgReplaceMSG(smsg_t *pThis, const uchar* pszMSG, int lenMSG);