diff --git a/backport-Fix-memory-leak-when-SetString.patch b/backport-Fix-memory-leak-when-SetString.patch new file mode 100644 index 0000000000000000000000000000000000000000..37eb1593378126e262b8ed945703f4b29cac9aa1 --- /dev/null +++ b/backport-Fix-memory-leak-when-SetString.patch @@ -0,0 +1,33 @@ +From b3ba1d7280bab1b623e1b2aaf390bbae8aa8c484 Mon Sep 17 00:00:00 2001 +From: seuzw930 <76191785+seuzw930@users.noreply.github.com> +Date: Sun, 14 Aug 2022 16:52:53 +0800 +Subject: [PATCH] Fix memory leak when SetString + +During SetString reassign to pThis->szVal.psz, pThis->szVal.psz might not null. It resulted in memory leak and this patch fixes this behaviour. + +The problem is mentioned here: +https://github.com/rsyslog/rsyslog/issues/4961From f65b8860358b7aaca76d3abe086ac2bf80e2079b Mon Sep 17 00:00:00 2001 + +Conflict:NA +Reference:https://github.com/rsyslog/rsyslog/commit/b3ba1d7280bab1b623e1b2aaf390bbae8aa8c484 +--- + runtime/prop.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/runtime/prop.c b/runtime/prop.c +index 866b691..c4de5d7 100644 +--- a/runtime/prop.c ++++ b/runtime/prop.c +@@ -84,6 +84,9 @@ static rsRetVal SetString(prop_t *pThis, const uchar *psz, const int len) + if(len < CONF_PROP_BUFSIZE) { + memcpy(pThis->szVal.sz, psz, len + 1); + } else { ++ if(pThis->szVal.psz != NULL) { ++ free(pThis->szVal.psz); ++ } + CHKmalloc(pThis->szVal.psz = malloc(len + 1)); + memcpy(pThis->szVal.psz, psz, len + 1); + } +-- +2.27.0 + diff --git a/backport-core-bugfix-correct-local-host-name-after-config-processing.patch b/backport-core-bugfix-correct-local-host-name-after-config-processing.patch new file mode 100644 index 0000000000000000000000000000000000000000..ee809fe5574ab847b2f6ced1e09fc0b5044af012 --- /dev/null +++ b/backport-core-bugfix-correct-local-host-name-after-config-processing.patch @@ -0,0 +1,258 @@ +From ba00a9f25293f72137c9a85010276cca014ae7f0 Mon Sep 17 00:00:00 2001 +From: Rainer Gerhards +Date: Wed, 31 Aug 2022 17:37:07 +0200 +Subject: [PATCH] core bugfix: correct local host name after config processing + +rsyslog.conf may affect the host's local name. These changes were +so far only activated after the first HUP. This patch now ensures +that the configured local host name is applied correctly throughout +all processing, including early startup. + +This patch causes a slight change of behaviour. However, the behaviour +was inconsitent before. Now it is consistent and according to the config. + +Please note: this patch also exposes a global entry point via "regular" +dynamic loading as this makes things much easier to do. This is in-line +with ongoing simplification effort. + +Finally, we also remove a CI test that we do no longer need because +the problem covered is now addressed differently and the original issue +can no longer occur. + +closes https://github.com/rsyslog/rsyslog/issues/4975 + +Conflict:NA +Reference:https://github.com/rsyslog/rsyslog/commit/ba00a9f25293f72137c9a85010276cca014ae7f0 +--- + runtime/glbl.c | 16 +++++++++++--- + runtime/glbl.h | 3 ++- + runtime/rsyslog.h | 2 +- + tests/Makefile.am | 6 ------ + tests/hostname-getaddrinfo-fail.sh | 34 ------------------------------ + tools/iminternal.c | 7 +++++- + tools/rsyslogd.c | 10 ++------- + 7 files changed, 24 insertions(+), 54 deletions(-) + delete mode 100755 tests/hostname-getaddrinfo-fail.sh + +diff --git a/runtime/glbl.c b/runtime/glbl.c +index 52a598f..4feefc4 100644 +--- a/runtime/glbl.c ++++ b/runtime/glbl.c +@@ -619,8 +619,8 @@ SetLocalHostName(uchar *const newname) + + /* return our local hostname. if it is not set, "[localhost]" is returned + */ +-static uchar* +-GetLocalHostName(void) ++uchar* ++glblGetLocalHostName(void) + { + uchar *pszRet; + +@@ -910,6 +910,8 @@ CODESTARTobjQueryInterface(glbl) + pIf->GetOption_DisallowWarning = getOption_DisallowWarning; + pIf->SetParseHOSTNAMEandTAG = setParseHOSTNAMEandTAG; + pIf->GetParseHOSTNAMEandTAG = getParseHOSTNAMEandTAG; ++ pIf->GetLocalHostName = glblGetLocalHostName; ++ pIf->SetLocalHostName = SetLocalHostName; + #define SIMP_PROP(name) \ + pIf->Get##name = Get##name; \ + pIf->Set##name = Set##name; +@@ -917,7 +919,6 @@ CODESTARTobjQueryInterface(glbl) + SIMP_PROP(DropMalPTRMsgs); + SIMP_PROP(mainqCnfObj); + SIMP_PROP(LocalFQDNName) +- SIMP_PROP(LocalHostName) + SIMP_PROP(LocalDomain) + SIMP_PROP(StripDomains) + SIMP_PROP(LocalHosts) +@@ -1541,6 +1542,15 @@ glblDoneLoadCnf(void) + stddbg = -1; + } + ++ /* we have now read the config. We need to query the local host name now ++ * as it was set by the config. ++ * ++ * Note: early messages are already emited, and have "[localhost]" as ++ * hostname. These messages are currently in iminternal queue. Once they ++ * are taken from that queue, the hostname will be adapted. ++ */ ++ queryLocalHostname(); ++ + finalize_it: RETiRet; + } + +diff --git a/runtime/glbl.h b/runtime/glbl.h +index 9ccf7b6..4cb5770 100644 +--- a/runtime/glbl.h ++++ b/runtime/glbl.h +@@ -8,7 +8,7 @@ + * Please note that there currently is no glbl.c file as we do not yet + * have any implementations. + * +- * Copyright 2008-2019 Rainer Gerhards and Adiscon GmbH. ++ * Copyright 2008-2022 Rainer Gerhards and Adiscon GmbH. + * + * This file is part of the rsyslog runtime library. + * +@@ -162,5 +162,6 @@ const uchar* glblGetOperatingStateFile(void); + int glblGetOversizeMsgInputMode(void); + int glblReportOversizeMessage(void); + void glblReportChildProcessExit(const uchar *name, pid_t pid, int status); ++uchar *glblGetLocalHostName(void); + + #endif /* #ifndef GLBL_H_INCLUDED */ +diff --git a/runtime/rsyslog.h b/runtime/rsyslog.h +index 6492eea..58f8219 100644 +--- a/runtime/rsyslog.h ++++ b/runtime/rsyslog.h +@@ -757,8 +757,8 @@ rsRetVal rsrtInit(const char **ppErrObj, obj_if_t *pObjIF); + rsRetVal rsrtExit(void); + int rsrtIsInit(void); + void rsrtSetErrLogger(void (*errLogger)(const int, const int, const uchar*)); +- + void dfltErrLogger(const int, const int, const uchar *errMsg); ++rsRetVal queryLocalHostname(void); + + + /* this define below is (later) intended to be used to implement empty +diff --git a/tests/Makefile.am b/tests/Makefile.am +index 5e4f4fe..34b5b38 100644 +--- a/tests/Makefile.am ++++ b/tests/Makefile.am +@@ -175,7 +175,6 @@ TESTS += \ + timestamp-mysql.sh \ + timestamp-pgsql.sh \ + timestamp-subseconds.sh \ +- hostname-getaddrinfo-fail.sh \ + msleep_usage_output.sh \ + mangle_qi_usage_output.sh \ + minitcpsrv_usage_output.sh \ +@@ -1608,10 +1607,6 @@ TESTS += \ + endif + endif # ENABLE_OMAMQP1 + +-# test samples... +-#empty-hostname.log: hostname-getaddrinfo-fail.log +-#hostname-getaddrinfo-fail.log: empty-hostname.log +- + endif # if ENABLE_TESTBENCH + + TESTS_ENVIRONMENT = RSYSLOG_MODDIR='$(abs_top_builddir)'/runtime/.libs/ +@@ -1648,7 +1643,6 @@ EXTRA_DIST= \ + config_enabled-off.sh \ + empty-app-name.sh \ + empty-hostname.sh \ +- hostname-getaddrinfo-fail.sh \ + hostname-with-slash-pmrfc5424.sh \ + hostname-with-slash-pmrfc3164.sh \ + pmrfc3164-msgFirstSpace.sh \ +diff --git a/tests/hostname-getaddrinfo-fail.sh b/tests/hostname-getaddrinfo-fail.sh +deleted file mode 100755 +index d14a1c3..0000000 +--- a/tests/hostname-getaddrinfo-fail.sh ++++ /dev/null +@@ -1,34 +0,0 @@ +-#!/bin/bash +-# This test check what happens if we cannot doe getaddrinfo early +-# in rsyslog startup (this has caused an error in the past). Even more +-# importantly, it checks that error messages can be issued very early +-# during startup. +-# Note that we use the override of the hostname to ensure we do not +-# accidentally get an acceptable FQDN-type hostname during testing. +-# +-# IMPORTANT: We cannot use the regular plumbing here, as our preload +-# interferes with socket operations (we cannot bind the port for some +-# reason). As we do not necessarily need the full plumbing for this +-# simple test, we emulate what we need. It's a bit ugly, but actually +-# the simplest way forward. +-# +-# This is part of the rsyslog testbench, licensed under ASL 2.0 +-. ${srcdir:=.}/diag.sh init +-skip_platform "AIX" "we cannot preload required dummy lib" +- +-echo 'action(type="omfile" file="'$RSYSLOG_DYNNAME'.out.log")' > ${RSYSLOG_DYNNAME}.conf +-LD_PRELOAD=".libs/liboverride_gethostname_nonfqdn.so:.libs/liboverride_getaddrinfo.so" \ +- ../tools/rsyslogd -C -n -i$RSYSLOG_DYNNAME.pid -M../runtime/.libs:../.libs -f${RSYSLOG_DYNNAME}.conf & +-wait_process_startup $RSYSLOG_DYNNAME +-sleep 1 # wait a bit so that rsyslog can do some processing... +-kill $(cat $RSYSLOG_DYNNAME.pid ) +- +-grep " nonfqdn " < $RSYSLOG_DYNNAME.out.log +-if [ ! $? -eq 0 ]; then +- echo "expected hostname \"nonfqdn\" not found in logs, $RSYSLOG_DYNNAME.out.log is:" +- cat $RSYSLOG_DYNNAME.out.log +- error_exit 1 +-fi; +- +-echo EVERYTHING OK - error messages are just as expected! +-exit_test +diff --git a/tools/iminternal.c b/tools/iminternal.c +index 52e9df8..c4dd548 100644 +--- a/tools/iminternal.c ++++ b/tools/iminternal.c +@@ -6,7 +6,7 @@ + * + * File begun on 2007-08-03 by RGerhards + * +- * Copyright 2007-2017 Rainer Gerhards and Adiscon GmbH. ++ * Copyright 2007-2022 Rainer Gerhards and Adiscon GmbH. + * + * This file is part of rsyslog. + * +@@ -37,6 +37,7 @@ + #include "syslogd.h" + #include "linkedlist.h" + #include "iminternal.h" ++#include "unicode-helper.h" + + static linkedList_t llMsgs; + static pthread_mutex_t mutList = PTHREAD_MUTEX_INITIALIZER; +@@ -137,6 +138,10 @@ rsRetVal iminternalRemoveMsg(smsg_t **ppMsg) + + pthread_mutex_lock(&mutList); + CHKiRet(llGetNextElt(&llMsgs, &llCookie, (void*)&pThis)); ++ if(!strcmp((char*)pThis->pMsg->pszHOSTNAME, "[localhost]")) { ++ /* early (pre-conf) startup message detected, need to set real hostname now */ ++ MsgSetHOSTNAME(pThis->pMsg, glblGetLocalHostName(), ustrlen(glblGetLocalHostName())); ++ } + *ppMsg = pThis->pMsg; + pThis->pMsg = NULL; /* we do no longer own it - important for destructor */ + +diff --git a/tools/rsyslogd.c b/tools/rsyslogd.c +index 8410d44..9dedd2f 100644 +--- a/tools/rsyslogd.c ++++ b/tools/rsyslogd.c +@@ -3,7 +3,7 @@ + * because it was either written from scratch by me (rgerhards) or + * contributors who agreed to ASL 2.0. + * +- * Copyright 2004-2019 Rainer Gerhards and Adiscon ++ * Copyright 2004-2022 Rainer Gerhards and Adiscon + * + * This file is part of rsyslog. + * +@@ -231,7 +231,7 @@ setsid(void) + #endif + + +-static rsRetVal ++rsRetVal + queryLocalHostname(void) + { + uchar *LocalHostName = NULL; +@@ -1384,12 +1384,6 @@ initAll(int argc, char **argv) + exit(1); /* "good" exit, leaving at init for fatal error */ + } + +- /* get our host and domain names - we need to do this early as we may emit +- * error log messages, which need the correct hostname. -- rgerhards, 2008-04-04 +- * But we need to have imInternal up first! +- */ +- queryLocalHostname(); +- + /* we now can emit error messages "the regular way" */ + + if(getenv("TZ") == NULL) { +-- +2.27.0 diff --git a/backport-core-bugfix-local-hostname-invalid-if-no-global-config-object-given.patch b/backport-core-bugfix-local-hostname-invalid-if-no-global-config-object-given.patch new file mode 100644 index 0000000000000000000000000000000000000000..1949f11fba98fa04b4cfadb53b89dd08c2fed7eb --- /dev/null +++ b/backport-core-bugfix-local-hostname-invalid-if-no-global-config-object-given.patch @@ -0,0 +1,45 @@ +From e2beca531157a4c0a27bcdda689bc53373e305b3 Mon Sep 17 00:00:00 2001 +From: Rainer Gerhards +Date: Thu, 20 Oct 2022 18:08:11 +0200 +Subject: [PATCH] core bugfix: local hostname invalid if no global() config + object given + +The local hostname is invalidly set to "[localhost]" on rsyslog startup +if no global() config object is present in rsyslog.conf. Sending a HUP +corrects the hostname. + +This is a regression from ba00a9f25293f + +closes https://github.com/rsyslog/rsyslog/issues/4975, +closes https://github.com/rsyslog/rsyslog/issues/4825From cfe12d3df739adc6e583e3d4dd798f492b0aa17e Mon Sep 17 00:00:00 2001 + +Conflict:NA +Reference:https://github.com/rsyslog/rsyslog/commit/e2beca531157a4c0a27bcdda689bc53373e305b3 +--- + runtime/glbl.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/runtime/glbl.c b/runtime/glbl.c +index ff11419..71c3989 100644 +--- a/runtime/glbl.c ++++ b/runtime/glbl.c +@@ -1567,6 +1567,7 @@ glblDoneLoadCnf(void) + stddbg = -1; + } + ++finalize_it: + /* we have now read the config. We need to query the local host name now + * as it was set by the config. + * +@@ -1575,8 +1576,7 @@ glblDoneLoadCnf(void) + * are taken from that queue, the hostname will be adapted. + */ + queryLocalHostname(); +- +-finalize_it: RETiRet; ++ RETiRet; + } + + +-- +2.27.0 diff --git a/rsyslog.spec b/rsyslog.spec index 1f573bc975dd845cb4b4fcf37d9de897039d3d66..c6e1dde72ea8cbb89080632796a4c82647d415a8 100644 --- a/rsyslog.spec +++ b/rsyslog.spec @@ -7,7 +7,7 @@ Name: rsyslog Version: 8.2110.0 -Release: 11 +Release: 12 Summary: The rocket-fast system for log processing License: (GPLv3+ and ASL 2.0) URL: http://www.rsyslog.com/ @@ -40,7 +40,10 @@ Patch6004: backport-Fix-non-null-terminated-string-used-with-strlen.patch Patch6005: backport-tcpsrv-do-not-decrease-number-of-to-be-processed-fds.patch Patch6006: backport-imptcp-bugfix-worker-thread-starvation-on-extreme-tr.patch Patch6007: backport-Fix-memory-leak-when-globally-de-initialize-GnuTLS.patch -Patch6008: backport-Fix-memory-leak-when-free-action-worker-data-table.patch +Patch6008: backport-Fix-memory-leak-when-free-action-worker-data-table.patch +Patch6009: backport-core-bugfix-correct-local-host-name-after-config-processing.patch +Patch6010: backport-Fix-memory-leak-when-SetString.patch +Patch6011: backport-core-bugfix-local-hostname-invalid-if-no-global-config-object-given.patch BuildRequires: gcc autoconf automake bison dos2unix flex pkgconfig python3-docutils libtool BuildRequires: libgcrypt-devel libuuid-devel zlib-devel krb5-devel libnet-devel gnutls-devel @@ -503,6 +506,9 @@ done %{_mandir}/man1/rscryutil.1.gz %changelog +* Sat Nov 19 2022 pengyi - 8.2110.0-12 +- backport patches from upstream + * Mon Oct 10 2022 huangduirong - 8.2110.0-11 - Type:NA - ID:NA