1 Star 0 Fork 38

pengyi37/rsyslog

forked from src-openEuler/rsyslog 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
backport-core-bugfix-template-system-may-generate-invalid-json.patch 2.00 KB
一键复制 编辑 原始数据 按行查看 历史
From 246b8d8553b6880146d6c489a28cf4bacea8a199 Mon Sep 17 00:00:00 2001
From: Rainer Gerhards <rgerhards@adiscon.com>
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
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/pengyi37/rsyslog.git
git@gitee.com:pengyi37/rsyslog.git
pengyi37
rsyslog
rsyslog
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385