1*4882a593SmuzhiyunFrom 81a07263f1e522a376d3a30f96f51df3f2879f8a Mon Sep 17 00:00:00 2001 2*4882a593SmuzhiyunFrom: Laszlo Varady <laszlo.varady@protonmail.com> 3*4882a593SmuzhiyunDate: Sat, 20 Aug 2022 12:22:44 +0200 4*4882a593SmuzhiyunSubject: [PATCH 2/8] syslogformat: add bug reproducer test for non-zero terminated 5*4882a593Smuzhiyun input 6*4882a593SmuzhiyunMIME-Version: 1.0 7*4882a593SmuzhiyunContent-Type: text/plain; charset=UTF-8 8*4882a593SmuzhiyunContent-Transfer-Encoding: 8bit 9*4882a593Smuzhiyun 10*4882a593SmuzhiyunCVE: CVE-2022-38725 11*4882a593Smuzhiyun 12*4882a593SmuzhiyunUpstream-Status: Backport 13*4882a593Smuzhiyun[https://github.com/syslog-ng/syslog-ng/commit/81a07263f1e522a376d3a30f96f51df3f2879f8a] 14*4882a593Smuzhiyun 15*4882a593SmuzhiyunSigned-off-by: László Várady <laszlo.varady@protonmail.com> 16*4882a593Smuzhiyun 17*4882a593SmuzhiyunSigned-off-by: Yogita Urade <yogita.urade@windriver.com> 18*4882a593Smuzhiyun--- 19*4882a593Smuzhiyun modules/syslogformat/CMakeLists.txt | 1 + 20*4882a593Smuzhiyun modules/syslogformat/Makefile.am | 2 + 21*4882a593Smuzhiyun modules/syslogformat/tests/CMakeLists.txt | 1 + 22*4882a593Smuzhiyun modules/syslogformat/tests/Makefile.am | 9 +++ 23*4882a593Smuzhiyun .../syslogformat/tests/test_syslog_format.c | 72 +++++++++++++++++++ 24*4882a593Smuzhiyun 5 files changed, 85 insertions(+) 25*4882a593Smuzhiyun create mode 100644 modules/syslogformat/tests/CMakeLists.txt 26*4882a593Smuzhiyun create mode 100644 modules/syslogformat/tests/Makefile.am 27*4882a593Smuzhiyun create mode 100644 modules/syslogformat/tests/test_syslog_format.c 28*4882a593Smuzhiyun 29*4882a593Smuzhiyundiff --git a/modules/syslogformat/CMakeLists.txt b/modules/syslogformat/CMakeLists.txt 30*4882a593Smuzhiyunindex 94ee01aa2..64848efee 100644 31*4882a593Smuzhiyun--- a/modules/syslogformat/CMakeLists.txt 32*4882a593Smuzhiyun+++ b/modules/syslogformat/CMakeLists.txt 33*4882a593Smuzhiyun@@ -14,3 +14,4 @@ add_module( 34*4882a593Smuzhiyun SOURCES ${SYSLOGFORMAT_SOURCES} 35*4882a593Smuzhiyun ) 36*4882a593Smuzhiyun 37*4882a593Smuzhiyun+add_test_subdirectory(tests) 38*4882a593Smuzhiyundiff --git a/modules/syslogformat/Makefile.am b/modules/syslogformat/Makefile.am 39*4882a593Smuzhiyunindex f13f88c1b..14cdf589d 100644 40*4882a593Smuzhiyun--- a/modules/syslogformat/Makefile.am 41*4882a593Smuzhiyun+++ b/modules/syslogformat/Makefile.am 42*4882a593Smuzhiyun@@ -31,3 +31,5 @@ modules_syslogformat_libsyslogformat_la_DEPENDENCIES = \ 43*4882a593Smuzhiyun modules/syslogformat modules/syslogformat/ mod-syslogformat: \ 44*4882a593Smuzhiyun modules/syslogformat/libsyslogformat.la 45*4882a593Smuzhiyun .PHONY: modules/syslogformat/ mod-syslogformat 46*4882a593Smuzhiyun+ 47*4882a593Smuzhiyun+include modules/syslogformat/tests/Makefile.am 48*4882a593Smuzhiyundiff --git a/modules/syslogformat/tests/CMakeLists.txt b/modules/syslogformat/tests/CMakeLists.txt 49*4882a593Smuzhiyunnew file mode 100644 50*4882a593Smuzhiyunindex 000000000..2e45b7194 51*4882a593Smuzhiyun--- /dev/null 52*4882a593Smuzhiyun+++ b/modules/syslogformat/tests/CMakeLists.txt 53*4882a593Smuzhiyun@@ -0,0 +1 @@ 54*4882a593Smuzhiyun+add_unit_test(CRITERION TARGET test_syslog_format DEPENDS syslogformat) 55*4882a593Smuzhiyundiff --git a/modules/syslogformat/tests/Makefile.am b/modules/syslogformat/tests/Makefile.am 56*4882a593Smuzhiyunnew file mode 100644 57*4882a593Smuzhiyunindex 000000000..7ee66a59c 58*4882a593Smuzhiyun--- /dev/null 59*4882a593Smuzhiyun+++ b/modules/syslogformat/tests/Makefile.am 60*4882a593Smuzhiyun@@ -0,0 +1,9 @@ 61*4882a593Smuzhiyun+modules_syslogformat_tests_TESTS = \ 62*4882a593Smuzhiyun+ modules/syslogformat/tests/test_syslog_format 63*4882a593Smuzhiyun+ 64*4882a593Smuzhiyun+check_PROGRAMS += ${modules_syslogformat_tests_TESTS} 65*4882a593Smuzhiyun+ 66*4882a593Smuzhiyun+EXTRA_DIST += modules/syslogformat/tests/CMakeLists.txt 67*4882a593Smuzhiyun+ 68*4882a593Smuzhiyun+modules_syslogformat_tests_test_syslog_format_CFLAGS = $(TEST_CFLAGS) -I$(top_srcdir)/modules/syslogformat 69*4882a593Smuzhiyun+modules_syslogformat_tests_test_syslog_format_LDADD = $(TEST_LDADD) $(PREOPEN_SYSLOGFORMAT) 70*4882a593Smuzhiyundiff --git a/modules/syslogformat/tests/test_syslog_format.c b/modules/syslogformat/tests/test_syslog_format.c 71*4882a593Smuzhiyunnew file mode 100644 72*4882a593Smuzhiyunindex 000000000..b247fe3c5 73*4882a593Smuzhiyun--- /dev/null 74*4882a593Smuzhiyun+++ b/modules/syslogformat/tests/test_syslog_format.c 75*4882a593Smuzhiyun@@ -0,0 +1,72 @@ 76*4882a593Smuzhiyun+/* 77*4882a593Smuzhiyun+ * Copyright (c) 2022 One Identity 78*4882a593Smuzhiyun+ * Copyright (c) 2022 László Várady 79*4882a593Smuzhiyun+ * 80*4882a593Smuzhiyun+ * This program is free software; you can redistribute it and/or modify it 81*4882a593Smuzhiyun+ * under the terms of the GNU General Public License version 2 as published 82*4882a593Smuzhiyun+ * by the Free Software Foundation, or (at your option) any later version. 83*4882a593Smuzhiyun+ * 84*4882a593Smuzhiyun+ * This program is distributed in the hope that it will be useful, 85*4882a593Smuzhiyun+ * but WITHOUT ANY WARRANTY; without even the implied warranty of 86*4882a593Smuzhiyun+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 87*4882a593Smuzhiyun+ * GNU General Public License for more details. 88*4882a593Smuzhiyun+ * 89*4882a593Smuzhiyun+ * You should have received a copy of the GNU General Public License 90*4882a593Smuzhiyun+ * along with this program; if not, write to the Free Software 91*4882a593Smuzhiyun+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 92*4882a593Smuzhiyun+ * 93*4882a593Smuzhiyun+ * As an additional exemption you are allowed to compile & link against the 94*4882a593Smuzhiyun+ * OpenSSL libraries as published by the OpenSSL project. See the file 95*4882a593Smuzhiyun+ * COPYING for details. 96*4882a593Smuzhiyun+ * 97*4882a593Smuzhiyun+ */ 98*4882a593Smuzhiyun+ 99*4882a593Smuzhiyun+#include <criterion/criterion.h> 100*4882a593Smuzhiyun+ 101*4882a593Smuzhiyun+#include "apphook.h" 102*4882a593Smuzhiyun+#include "cfg.h" 103*4882a593Smuzhiyun+#include "syslog-format.h" 104*4882a593Smuzhiyun+#include "logmsg/logmsg.h" 105*4882a593Smuzhiyun+#include "msg-format.h" 106*4882a593Smuzhiyun+#include "scratch-buffers.h" 107*4882a593Smuzhiyun+ 108*4882a593Smuzhiyun+#include <string.h> 109*4882a593Smuzhiyun+ 110*4882a593Smuzhiyun+GlobalConfig *cfg; 111*4882a593Smuzhiyun+MsgFormatOptions parse_options; 112*4882a593Smuzhiyun+ 113*4882a593Smuzhiyun+static void 114*4882a593Smuzhiyun+setup(void) 115*4882a593Smuzhiyun+{ 116*4882a593Smuzhiyun+ app_startup(); 117*4882a593Smuzhiyun+ syslog_format_init(); 118*4882a593Smuzhiyun+ 119*4882a593Smuzhiyun+ cfg = cfg_new_snippet(); 120*4882a593Smuzhiyun+ msg_format_options_defaults(&parse_options); 121*4882a593Smuzhiyun+} 122*4882a593Smuzhiyun+ 123*4882a593Smuzhiyun+static void 124*4882a593Smuzhiyun+teardown(void) 125*4882a593Smuzhiyun+{ 126*4882a593Smuzhiyun+ scratch_buffers_explicit_gc(); 127*4882a593Smuzhiyun+ app_shutdown(); 128*4882a593Smuzhiyun+ cfg_free(cfg); 129*4882a593Smuzhiyun+} 130*4882a593Smuzhiyun+ 131*4882a593Smuzhiyun+TestSuite(syslog_format, .init = setup, .fini = teardown); 132*4882a593Smuzhiyun+ 133*4882a593Smuzhiyun+Test(syslog_format, parser_should_not_spin_on_non_zero_terminated_input, .timeout = 10) 134*4882a593Smuzhiyun+{ 135*4882a593Smuzhiyun+ const gchar *data = "<182>2022-08-17T05:02:28.217 mymachine su: 'su root' failed for lonvick on /dev/pts/8"; 136*4882a593Smuzhiyun+ /* chosen carefully to reproduce a bug */ 137*4882a593Smuzhiyun+ gsize data_length = 27; 138*4882a593Smuzhiyun+ 139*4882a593Smuzhiyun+ msg_format_options_init(&parse_options, cfg); 140*4882a593Smuzhiyun+ LogMessage *msg = msg_format_construct_message(&parse_options, (const guchar *) data, data_length); 141*4882a593Smuzhiyun+ 142*4882a593Smuzhiyun+ gsize problem_position; 143*4882a593Smuzhiyun+ cr_assert(syslog_format_handler(&parse_options, msg, (const guchar *) data, data_length, &problem_position)); 144*4882a593Smuzhiyun+ 145*4882a593Smuzhiyun+ msg_format_options_destroy(&parse_options); 146*4882a593Smuzhiyun+ log_msg_unref(msg); 147*4882a593Smuzhiyun+} 148*4882a593Smuzhiyun-- 149*4882a593Smuzhiyun2.34.1 150*4882a593Smuzhiyun 151