omfile bugfix: segfault when empty filename is given

closes https://github.com/rsyslog/rsyslog/issues/2417
This commit is contained in:
Rainer Gerhards 2018-04-03 12:26:52 +02:00
parent 1c7d675f15
commit 3d7acd2656
4 changed files with 62 additions and 2 deletions

View File

@ -58,6 +58,8 @@ TESTS += \
invalid_nested_include.sh \
omfwd-keepalive.sh \
omfile-read-only-errmsg.sh \
omfile-null-filename.sh \
omfile-whitespace-filename.sh \
omfile-read-only.sh \
omfile_both_files_set.sh \
msgvar-concurrency.sh \
@ -1043,6 +1045,8 @@ EXTRA_DIST= \
testsuites/stop-msgvar.conf \
omfwd-keepalive.sh \
omfile-read-only-errmsg.sh \
omfile-null-filename.sh \
omfile-whitespace-filename.sh \
omfile-read-only.sh \
omfile_both_files_set.sh \
msgvar-concurrency.sh \

22
tests/omfile-null-filename.sh Executable file
View File

@ -0,0 +1,22 @@
#!/bin/bash
# check that omfile does not segfault when filename is given but empty.
# addd 2018-04-03 by RGerhards, released under ASL 2.0
. $srcdir/diag.sh init
. $srcdir/diag.sh generate-conf
. $srcdir/diag.sh add-conf '
action(type="omfile" file="")
action(type="omfile" file="rsyslog.out.log")
'
. $srcdir/diag.sh startup
. $srcdir/diag.sh shutdown-when-empty
. $srcdir/diag.sh wait-shutdown
grep "parameter must be given" rsyslog.out.log > /dev/null
if [ $? -ne 0 ]; then
echo
echo "FAIL: expected error message not found. rsyslog.out.log is:"
cat rsyslog.out.log
. $srcdir/diag.sh error-exit 1
fi
. $srcdir/diag.sh exit

View File

@ -0,0 +1,21 @@
#!/bin/bash
# addd 2018-04-03 by RGerhards, released under ASL 2.0
. $srcdir/diag.sh init
. $srcdir/diag.sh generate-conf
. $srcdir/diag.sh add-conf '
action(type="omfile" file=" ")
action(type="omfile" file="rsyslog.out.log")
'
. $srcdir/diag.sh startup
. $srcdir/diag.sh shutdown-when-empty
. $srcdir/diag.sh wait-shutdown
grep "only of whitespace" rsyslog.out.log > /dev/null
if [ $? -ne 0 ]; then
echo
echo "FAIL: expected error message not found. rsyslog.out.log is:"
cat rsyslog.out.log
. $srcdir/diag.sh error-exit 1
fi
. $srcdir/diag.sh exit

View File

@ -17,7 +17,7 @@
* pipes. These have been moved to ompipe, to reduced the entanglement
* between the two different functionalities. -- rgerhards
*
* Copyright 2007-2017 Adiscon GmbH.
* Copyright 2007-2018 Adiscon GmbH.
*
* This file is part of rsyslog.
*
@ -1323,12 +1323,25 @@ CODESTARTnewActInst
}
}
if(pData->fname == NULL) {
if(pData->fname == NULL || *pData->fname == '\0') {
parser_errmsg("omfile: either the \"file\" or "
"\"dynfile\" parameter must be given");
ABORT_FINALIZE(RS_RET_MISSING_CNFPARAMS);
}
int allWhiteSpace = 1;
for(const char *p = (const char*) pData->fname ; *p ; ++p) {
if(!isspace(*p)) {
allWhiteSpace = 0;
break;
}
}
if(allWhiteSpace) {
parser_errmsg("omfile: \"file\" or \"dynfile\" parameter "
"consist only of whitespace - this is not permitted");
ABORT_FINALIZE(RS_RET_MISSING_CNFPARAMS);
}
if(pData->sigprovName != NULL) {
initSigprov(pData, lst);
}