blob: b42618048e880dffdaa98458b1527d35a2baedbb [file] [log] [blame]
From 3a10a78edeef9725f69a24d633bb394e365145f0 Mon Sep 17 00:00:00 2001
From: Janmejay Singh <singh.janmejay@gmail.com>
Date: Wed, 30 Sep 2015 17:24:38 +0530
Subject: [PATCH] Fixed lookup-table reload bug, which ignored table-length of
reloaded table, resulting in additional entries being invisible while
looking-up (binary-search would work with old-table-length). This would be a
security-issue or may cause a crash if reloaded table is actually smaller
(memory access beyond table).
---
runtime/lookup.c | 1 +
tests/Makefile.am | 5 +++++
tests/diag.sh | 4 ++++
tests/lookup_table.sh | 24 ++++++++++++++++++++++++
tests/testsuites/lookup_table.conf | 9 +++++++++
tests/testsuites/xlate.lkp_tbl | 5 +++++
tests/testsuites/xlate_more.lkp_tbl | 6 ++++++
7 files changed, 55 insertions(+)
create mode 100755 tests/lookup_table.sh
create mode 100644 tests/testsuites/lookup_table.conf
create mode 100644 tests/testsuites/xlate.lkp_tbl
create mode 100644 tests/testsuites/xlate_more.lkp_tbl
diff --git a/runtime/lookup.c b/runtime/lookup.c
index 096bf09..5aa00b9 100644
--- a/runtime/lookup.c
+++ b/runtime/lookup.c
@@ -203,6 +203,7 @@ lookupReload(lookup_t *pThis)
}
free(pThis->d.strtab);
pThis->d.strtab = newlu.d.strtab; /* hand table AND ALL STRINGS over! */
+ pThis->nmemb = newlu.nmemb;
pthread_rwlock_unlock(&pThis->rwlock);
errmsg.LogError(0, RS_RET_OK, "lookup table '%s' reloaded from file '%s'",
pThis->name, pThis->filename);
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d77728a..49cb641 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -130,6 +130,7 @@ TESTS += \
incltest_dir_wildcard.sh \
incltest_dir_empty_wildcard.sh \
linkedlistqueue.sh \
+ lookup_table.sh \
key_dereference_on_uninitialized_variable_space.sh
@@ -860,6 +861,10 @@ EXTRA_DIST= \
testsuites/rscript_re_extract.conf \
rscript_re_match.sh \
testsuites/rscript_re_match.conf \
+ lookup_table.sh \
+ testsuites/lookup_table.conf \
+ testsuites/xlate.lkp_tbl \
+ testsuites/xlate_more.lkp_tbl \
cfg.sh
# TODO: re-enable
diff --git a/tests/diag.sh b/tests/diag.sh
index 95d6adb..c489fff 100755
--- a/tests/diag.sh
+++ b/tests/diag.sh
@@ -195,6 +195,10 @@ case $1 in
echo WaitMainQueueEmpty | ./diagtalker || . $srcdir/diag.sh error-exit $?
fi
;;
+ 'issue-HUP') # shut rsyslogd down when main queue is empty. $2 is the instance.
+ kill -HUP `cat rsyslog$2.pid`
+ ./msleep 1000
+ ;;
'shutdown-when-empty') # shut rsyslogd down when main queue is empty. $2 is the instance.
if [ "$2" == "2" ]
then
diff --git a/tests/lookup_table.sh b/tests/lookup_table.sh
new file mode 100755
index 0000000..fae2fab
--- /dev/null
+++ b/tests/lookup_table.sh
@@ -0,0 +1,24 @@
+#!/bin/bash
+# added 2015-09-30 by singh.janmejay
+# This file is part of the rsyslog project, released under ASL 2.0
+echo ===============================================================================
+echo \[lookup_table_reload.sh\]: test for lookup-table and HUP based reloading of it
+. $srcdir/diag.sh init
+cp $srcdir/testsuites/xlate.lkp_tbl $srcdir/xlate.lkp_tbl
+. $srcdir/diag.sh startup lookup_table.conf
+. $srcdir/diag.sh injectmsg 0 3
+. $srcdir/diag.sh wait-queueempty
+. $srcdir/diag.sh content-check "msgnum:00000000: foo_old"
+. $srcdir/diag.sh content-check "msgnum:00000001: bar_old"
+. $srcdir/diag.sh assert-content-missing "baz"
+cp $srcdir/testsuites/xlate_more.lkp_tbl $srcdir/xlate.lkp_tbl
+. $srcdir/diag.sh issue-HUP
+. $srcdir/diag.sh injectmsg 0 3
+echo doing shutdown
+. $srcdir/diag.sh shutdown-when-empty
+echo wait on shutdown
+. $srcdir/diag.sh wait-shutdown
+. $srcdir/diag.sh content-check "msgnum:00000000: foo_new"
+. $srcdir/diag.sh content-check "msgnum:00000001: bar_new"
+. $srcdir/diag.sh content-check "msgnum:00000002: baz"
+. $srcdir/diag.sh exit
diff --git a/tests/testsuites/lookup_table.conf b/tests/testsuites/lookup_table.conf
new file mode 100644
index 0000000..29bd805
--- /dev/null
+++ b/tests/testsuites/lookup_table.conf
@@ -0,0 +1,9 @@
+$IncludeConfig diag-common.conf
+
+lookup_table(name="xlate" file="xlate.lkp_tbl")
+
+template(name="outfmt" type="string" string="- %msg% %$.lkp%\n")
+
+set $.lkp = lookup("xlate", $msg);
+
+action(type="omfile" file="./rsyslog.out.log" template="outfmt")
diff --git a/tests/testsuites/xlate.lkp_tbl b/tests/testsuites/xlate.lkp_tbl
new file mode 100644
index 0000000..30e2796
--- /dev/null
+++ b/tests/testsuites/xlate.lkp_tbl
@@ -0,0 +1,5 @@
+{
+ "table":[
+ {"index":" msgnum:00000000:", "value":"foo_old" },
+ {"index":" msgnum:00000001:", "value":"bar_old" }]
+}
diff --git a/tests/testsuites/xlate_more.lkp_tbl b/tests/testsuites/xlate_more.lkp_tbl
new file mode 100644
index 0000000..2d3f452
--- /dev/null
+++ b/tests/testsuites/xlate_more.lkp_tbl
@@ -0,0 +1,6 @@
+{
+ "table":[
+ {"index":" msgnum:00000000:", "value":"foo_new" },
+ {"index":" msgnum:00000001:", "value":"bar_new" },
+ {"index":" msgnum:00000002:", "value":"baz" }]
+}