From 5cea9153e226711fdd27793cff3e26ffd1587a38 Mon Sep 17 00:00:00 2001 From: pengyi37 Date: Tue, 4 Apr 2023 06:53:36 +0000 Subject: [PATCH] add backport-core-bugfix-template-system-may-generate-invalid-json.patch add backport-omprog-bugfix-invalid-status-handling-at-called-prog.patch Signed-off-by: pengyi37 --- ...ate-system-may-generate-invalid-json.patch | 66 +++++++++++++++++++ ...valid-status-handling-at-called-prog.patch | 47 +++++++++++++ rsyslog.spec | 13 +++- 3 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 backport-core-bugfix-template-system-may-generate-invalid-json.patch create mode 100644 backport-omprog-bugfix-invalid-status-handling-at-called-prog.patch diff --git a/backport-core-bugfix-template-system-may-generate-invalid-json.patch b/backport-core-bugfix-template-system-may-generate-invalid-json.patch new file mode 100644 index 0000000..27c9d93 --- /dev/null +++ b/backport-core-bugfix-template-system-may-generate-invalid-json.patch @@ -0,0 +1,66 @@ +From 246b8d8553b6880146d6c489a28cf4bacea8a199 Mon Sep 17 00:00:00 2001 +From: Rainer Gerhards +Date: Fri, 30 Dec 2022 17:13:17 +0100 +Subject: [PATCH] core bugfix: template system may generate invalid json + +When +- a list template +- is created with option.jsonf="on" +- and the last list element is a property with onEmpty="skip" +- and that property is actually empty +invalid JSON is generated. + +The JSON string in this case ends with ", " instead of "}\n". This +patch fixes the issue. + +closes https://github.com/rsyslog/rsyslog/issues/5050 +--- + +Conflict:NA +Reference:https://github.com/rsyslog/rsyslog/commit/246b8d8553b6880146d6c489a28cf4bacea8a199 +--- + template.c | 16 +++++++++++++--- + 1 file changed, 13 insertions(+), 3 deletions(-) + +diff --git a/template.c b/template.c +index 21d8b8d..18bcda7 100644 +--- a/template.c ++++ b/template.c +@@ -163,6 +163,7 @@ tplToString(struct template *__restrict__ const pTpl, + unsigned short bMustBeFreed = 0; + uchar *pVal; + rs_size_t iLenVal = 0; ++ int need_comma = 0; + + if(pTpl->pStrgen != NULL) { + CHKiRet(pTpl->pStrgen(pMsg, iparam)); +@@ -230,15 +231,24 @@ tplToString(struct template *__restrict__ const pTpl, + if(iBuf + iLenVal + extra_space >= iparam->lenBuf) /* we reserve one char for the final \0! */ + CHKiRet(ExtendBuf(iparam, iBuf + iLenVal + 1)); + ++ if(need_comma) { ++ memcpy(iparam->param + iBuf, ", ", 2); ++ iBuf += 2; ++ } + memcpy(iparam->param + iBuf, pVal, iLenVal); + iBuf += iLenVal; + if(pTpl->optFormatEscape == JSONF) { +- memcpy(iparam->param + iBuf, +- (pTpe->pNext == NULL) ? "}\n" : ", ", 2); +- iBuf += 2; ++ need_comma = 1; + } + } + ++ if((pTpl->optFormatEscape == JSONF) && (pTpe->pNext == NULL)) { ++ /* space was reserved while processing field above ++ (via extra_space in ExtendBuf() new size formula. */ ++ memcpy(iparam->param + iBuf, "}\n", 2); ++ iBuf += 2; ++ } ++ + if(bMustBeFreed) { + free(pVal); + bMustBeFreed = 0; +-- +2.27.0 \ No newline at end of file diff --git a/backport-omprog-bugfix-invalid-status-handling-at-called-prog.patch b/backport-omprog-bugfix-invalid-status-handling-at-called-prog.patch new file mode 100644 index 0000000..cf40b4d --- /dev/null +++ b/backport-omprog-bugfix-invalid-status-handling-at-called-prog.patch @@ -0,0 +1,47 @@ +From 1128d320750fb6cfe57b8ad53ef1d5ddf80c81cf Mon Sep 17 00:00:00 2001 +From: Rainer Gerhards +Date: Sun, 4 Dec 2022 16:05:22 +0100 +Subject: [PATCH] omprog bugfix: invalid status handling at called program + +There is a bug when external program *startup* does not return "OK". This +can also lead to a misadressing with potentially a segfault (very unlikely). +Note that no problem exists once the initializiation phase of the external +program is finished and regular message transfer runs. + +The problem basically is that for a startup failure, the control data for +that external program instance is freed on error. Unfortunately, that state +data is needed later on to detect a suspended instance. We now keep the control +data even on init failure (as we then need to do normal control options). + +closes https://github.com/rsyslog/rsyslog/issues/4967 +--- +Conflict:NA +Reference:https://github.com/rsyslog/rsyslog/commit/1128d320750fb6cfe57b8ad53ef1d5ddf80c81cf +--- + plugins/omprog/omprog.c | 4 +--- + 1 file changed, 1 insertion(+), 3 deletions(-) + +diff --git a/plugins/omprog/omprog.c b/plugins/omprog/omprog.c +index 4f46f92..dd83e93 100644 +--- a/plugins/omprog/omprog.c ++++ b/plugins/omprog/omprog.c +@@ -379,6 +379,7 @@ cleanupChild(instanceData *pData, childProcessCtx_t *pChildCtx) + static void + terminateChild(instanceData *pData, childProcessCtx_t *pChildCtx) + { ++ DBGPRINTF("terminateChild called\n"); + assert(pChildCtx->bIsRunning); + + if (pData->bSignalOnClose) { +@@ -927,9 +928,6 @@ CODESTARTcreateWrkrInstance + } + + finalize_it: +- if(iRet != RS_RET_OK && !pWrkrData->pData->bForceSingleInst) { +- free(pWrkrData->pChildCtx); +- } + ENDcreateWrkrInstance + + +-- +2.27.0 \ No newline at end of file diff --git a/rsyslog.spec b/rsyslog.spec index 97e11e0..eb327a0 100644 --- a/rsyslog.spec +++ b/rsyslog.spec @@ -7,7 +7,7 @@ Name: rsyslog Version: 8.2210.0 -Release: 1 +Release: 2 Summary: The rocket-fast system for log processing License: (GPLv3+ and ASL 2.0) URL: http://www.rsyslog.com/ @@ -32,7 +32,9 @@ Patch9005: print-main-queue-info-to-journal-when-receive-USR1-signal.patch %endif Patch6000: backport-core-bugfix-local-hostname-invalid-if-no-global-config-object-given.patch -Patch6001: backport-imtcp-bugfix-legacy-config-directives-did-no-longer-work.patch +Patch6001: backport-imtcp-bugfix-legacy-config-directives-did-no-longer-work.patch +Patch6002: backport-core-bugfix-template-system-may-generate-invalid-json.patch +Patch6003: backport-omprog-bugfix-invalid-status-handling-at-called-prog.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 @@ -507,6 +509,13 @@ done %{_mandir}/man1/rscryutil.1.gz %changelog +* Tue Apr 4 2023 pengyi - 8.2210.0-2 +- Type:bugfix +- CVE:NA +- SUG:NA +- DESC:omprog bugfix: invalid status handling at called program + core bugfix: template system may generate invalid json + * Sat Feb 4 2023 pengyi - 8.2210.0-1 - Type:NA - ID:NA -- Gitee