From 086db18cc304c9aff082e8ee4adfdadeacfa5c39 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 20 Sep 2011 15:16:53 +0200 Subject: bugfix: potential abort if ultra-large file io buffers are used and dynafile cache exhausts address space (primarily a problem on 32 bit platforms) --- tools/omfile.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'tools') diff --git a/tools/omfile.c b/tools/omfile.c index 88e8115e..f7339300 100644 --- a/tools/omfile.c +++ b/tools/omfile.c @@ -355,6 +355,7 @@ prepareFile(instanceData *pData, uchar *newFileName) int fd; DEFiRet; + pData->pStrm = NULL; if(access((char*)newFileName, F_OK) == 0) { if(pData->bForceChown) { /* Try to fix wrong ownership set by someone else. Note that this code @@ -440,6 +441,11 @@ prepareFile(instanceData *pData, uchar *newFileName) CHKiRet(strm.ConstructFinalize(pData->pStrm)); finalize_it: + if(iRet != RS_RET_OK) { + if(pData->pStrm != NULL) { + strm.Destruct(&pData->pStrm); + } + } RETiRet; } @@ -516,7 +522,7 @@ prepareDynFile(instanceData *pData, uchar *newFileName, unsigned iMsgOpts) 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. + * but it could be triggered in the common case of a failed open() system call. * rgerhards, 2010-03-22 */ pData->pStrm = NULL; @@ -545,8 +551,8 @@ prepareDynFile(instanceData *pData, uchar *newFileName, unsigned iMsgOpts) /* Ok, we finally can open the file */ localRet = prepareFile(pData, newFileName); /* ignore exact error, we check fd below */ - /* file is either open now or an error state set */ // RG: better check localRet? - if(pData->pStrm == NULL) { + /* check if we had an error */ + if(localRet != RS_RET_OK) { /* do not report anything if the message is an internally-generated * message. Otherwise, we could run into a never-ending loop. The bad * news is that we also lose errors on startup messages, but so it is. @@ -554,7 +560,7 @@ prepareDynFile(instanceData *pData, uchar *newFileName, unsigned iMsgOpts) if(iMsgOpts & INTERNAL_MSG) { DBGPRINTF("Could not open dynaFile, discarding message\n"); } else { - errmsg.LogError(0, NO_ERRCODE, "Could not open dynamic file '%s' - discarding message", newFileName); + errmsg.LogError(0, NO_ERRCODE, "Could not open dynamic file '%s' [state %d] - discarding message", newFileName, localRet); } ABORT_FINALIZE(localRet); } -- cgit