Skip to content

Commit 50cab9f

Browse files
committed
FEATURE: liblognorm: name-valie-list quoting support
liblognorm pull request #234 parseNameValue: fix no quoting support rsyslog/liblognorm#234
1 parent 8b4d5da commit 50cab9f

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
From ec179e3e721663513ada30f1776b21468e23d50d Mon Sep 17 00:00:00 2001
2+
From: Benoit DOLEZ <[email protected]>
3+
Date: Tue, 4 Feb 2020 09:28:48 +0100
4+
Subject: [PATCH] parseNameValue: fix no quoting support
5+
6+
Function description announce support of quoted variable :
7+
- name=value
8+
- name="value"
9+
- name='value'
10+
11+
... but there is nothing in the code to really support quoted string.
12+
I had small fixes to support it.
13+
14+
My tests :
15+
$ cat > test.txt <<EOF
16+
a=
17+
a=123
18+
a=123
19+
a='123'
20+
a="123"
21+
a=123 b=456
22+
a=123 b="456"
23+
a=123 b="456" c=
24+
a=123 b="456'789" c=
25+
a=123 b="456 789" c=
26+
a=123 b="456 789' c=
27+
a=123 b=456 789 c=
28+
EOF
29+
30+
$ cat > test.rb << EOF
31+
version=2
32+
rule=test-ok:%[
33+
{"type": "name-value-list"}
34+
]%
35+
EOF
36+
37+
$ cat test.txt | ./lognormalizer -r test.rb -T
38+
{ "event.tags": [ "test-ok" ] }
39+
{ "event.tags": [ "test-ok" ] }
40+
{ "event.tags": [ "test-ok" ] }
41+
{ "event.tags": [ "test-ok" ] }
42+
{ "event.tags": [ "test-ok" ] }
43+
{ "event.tags": [ "test-ok" ] }
44+
{ "event.tags": [ "test-ok" ] }
45+
{ "event.tags": [ "test-ok" ] }
46+
{ "event.tags": [ "test-ok" ] }
47+
{ "event.tags": [ "test-ok" ] }
48+
{ "originalmsg": "a=123 b=\"456 789' c= ", "unparsed-data": "a=123 b=\"456 789' c= " }
49+
{ "originalmsg": "a=123 b=456 789 c= ", "unparsed-data": "a=123 b=456 789 c= " }
50+
---
51+
src/parser.c | 14 +++++++++++++-
52+
1 file changed, 13 insertions(+), 1 deletion(-)
53+
54+
diff --git a/src/parser.c b/src/parser.c
55+
index 7343d84..8253791 100644
56+
--- a/src/parser.c
57+
+++ b/src/parser.c
58+
@@ -2420,11 +2420,23 @@ parseNameValue(npb_t *const npb,
59+
const size_t lenName = i - iName;
60+
++i; /* skip '=' */
61+
62+
+ char quoting = npb->str[i]; // end of string
63+
+ if (i < npb->strLen && (quoting == '"' || quoting == '\''))
64+
+ ++i;
65+
+ else
66+
+ quoting = 0; // str[i] can't be null, is a good default value
67+
+
68+
const size_t iVal = i;
69+
- while(i < npb->strLen && !isspace(npb->str[i]))
70+
+ while(i < npb->strLen &&
71+
+ ((quoting && npb->str[i] != quoting) || (!quoting && !isspace(npb->str[i]))))
72+
++i;
73+
const size_t lenVal = i - iVal;
74+
75+
+ if (i < npb->strLen && npb->str[i] == quoting)
76+
+ ++i;
77+
+ else if (quoting)
78+
+ goto done;
79+
+
80+
/* parsing OK */
81+
*offs = i;
82+
r = 0;
83+
--
84+
2.21.1
85+

SPECS/rsyslog.spec

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
Summary: Rsyslog v8 package by Zenetys
2121
Name: rsyslog8z
2222
Version: 8.2006.0
23-
Release: 1%{?dist}.zenetys
23+
Release: 2%{?dist}.zenetys
2424
License: GPLv3+ and ASL 2.0
2525
Group: System Environment/Daemons
2626

@@ -45,6 +45,7 @@ Patch0: rsyslog-systemd-centos8.patch
4545
%endif
4646

4747
Patch200: liblognorm-cef-first-extension.patch
48+
Patch201: liblognorm-parseNameValue-fix-no-quoting-support.patch
4849

4950
URL: http://www.rsyslog.com/
5051
Vendor: Adiscon GmbH, Deutschland
@@ -144,6 +145,7 @@ cd ..
144145

145146
cd %{liblognorm}
146147
%patch200 -p1
148+
%patch201 -p1
147149
cd ..
148150

149151
%build

0 commit comments

Comments
 (0)