components/rsyslog/patches/01-dynafile_segfault.patch
author Mike Sullivan <Mike.Sullivan@Oracle.COM>
Fri, 08 Apr 2016 11:57:35 -0700
changeset 5744 659a5b9e36ea
parent 5141 f6119b010ffa
permissions -rw-r--r--
Close of build 97.

# This patch addresses a few issues in the dynafile actions for omfiles.
# Specifcally if the target file cannot be opened, rsyslogd will segfault.
# The patch is from an upstream pull:
# https://github.com/rsyslog/rsyslog/pull/450/commits
# and should be removed when rsyslog is moved to or past version 8.12.0

--- rsyslog/runtime/srutils.c.1	Wed Nov 25 10:48:03 2015
+++ rsyslog/runtime/srutils.c	Wed Nov 25 10:49:05 2015
@@ -198,7 +198,6 @@
         uchar *p;
         uchar *pszWork;
         size_t len;
-	int err;
 	int iTry = 0;
 	int bErr = 0;

@@ -215,7 +214,7 @@
                         *p = '\0';
 again:
                         if(access((char*)pszWork, F_OK)) {
-                                if((err = mkdir((char*)pszWork, mode)) == 0) {
+                                if(mkdir((char*)pszWork, mode) == 0) {
 					if(uid != (uid_t) -1 || gid != (gid_t) -1) {
 						/* we need to set owner/group */
 						if(chown((char*)pszWork, uid, gid) != 0)
@@ -226,7 +225,7 @@
 							 */
 					}
 				} else {
-					if(err == EEXIST && iTry == 0) {
+					if(errno == EEXIST && iTry == 0) {
 						iTry = 1;
 						goto again;
 						}
--- rsyslog/tools/omfile.c.1	Wed Nov 25 10:39:15 2015
+++ rsyslog/tools/omfile.c	Wed Nov 25 10:47:18 2015
@@ -723,12 +723,6 @@
 	/* we have not found an entry */
 	STATSCOUNTER_INC(pData->ctrMiss, pData->mutCtrMiss);

-	/* invalidate iCurrElt as we may error-exit out of this function when the currrent
-	 * iCurrElt has been freed or otherwise become unusable. This is a precaution, and
-	 * performance-wise it may be better to do that in each of the exits. However, that
-	 * is error-prone, so I prefer to do it here. -- rgerhards, 2010-03-02
-	 */
-	pData->iCurrElt = -1;
 	/* similarly, we need to set the current pStrm to NULL, because otherwise, if prepareFile() fails,
 	 * we may end up using an old stream. This bug depends on how exactly prepareFile fails,
 	 * but it could be triggered in the common case of a failed open() system call.
@@ -779,7 +773,8 @@
 	DBGPRINTF("Added new entry %d for file cache, file '%s'.\n", iFirstFree, newFileName);

 finalize_it:
-	pCache[pData->iCurrElt]->nInactive = 0;
+	if(iRet == RS_RET_OK)
+		pCache[pData->iCurrElt]->nInactive = 0;
 	RETiRet;
 }