summaryrefslogtreecommitdiff
blob: b42618048e880dffdaa98458b1527d35a2baedbb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
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" }]
+}