From 192fa5afe641999549615abc43a6d3f6925f6a2a Mon Sep 17 00:00:00 2001 From: Kenneth Shelton Date: Wed, 9 Aug 2017 18:24:02 +0000 Subject: [PATCH] Made ipv6 behave more like ipv4 (Doesn't have to end in space) Fixed null ptr deref --- src/parser.c | 9 +++++++-- tests/field_ipv6.sh | 2 +- tests/field_ipv6_jsoncnf.sh | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/parser.c b/src/parser.c index 27794a2b..2b9b3ad7 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1625,7 +1625,9 @@ PARSER_Parse(OpQuotedString) /* create JSON value to save quoted string contents */ CHKN(cstr = strndup((char*)c + *offs + 1, *parsed - 2)); } - CHKN(*value = json_object_new_string(cstr)); + if (value != NULL) { + CHKN(*value = json_object_new_string(cstr)); + } r = 0; /* success */ done: @@ -2139,11 +2141,14 @@ PARSER_Parse(IPv6) if(skipIPv6AddrBlock(npb, &i) != 0) goto done; nBlocks++; if(i == npb->strLen) goto chk_ok; - if(isspace(c[i])) goto chk_ok; + /* no more valid chars, check address */ + if(c[i] != ':' && c[i] != '.') goto chk_ok; if(c[i] == '.'){ /* IPv4 processing! */ hasIPv4 = 1; break; } + /* maximum blocks consumed and not ipv4, check if valid */ + if (nBlocks == 8) goto chk_ok; if(c[i] != ':') goto done; i++; /* "eat" ':' */ if(i == npb->strLen) goto chk_ok; diff --git a/tests/field_ipv6.sh b/tests/field_ipv6.sh index 3887a55d..57327d87 100755 --- a/tests/field_ipv6.sh +++ b/tests/field_ipv6.sh @@ -41,7 +41,7 @@ execute 'ABCD:EF01:2345:6789:ABCD:EF01:2345::6789' # :: with too many blocks assert_output_json_eq '{ "originalmsg": "ABCD:EF01:2345:6789:ABCD:EF01:2345::6789", "unparsed-data": "ABCD:EF01:2345:6789:ABCD:EF01:2345::6789" }' execute 'ABCD:EF01:2345:6789:ABCD:EF01:2345:1:6798' # too many blocks (9) -assert_output_json_eq '{"originalmsg": "ABCD:EF01:2345:6789:ABCD:EF01:2345:1:6798", "unparsed-data": "ABCD:EF01:2345:6789:ABCD:EF01:2345:1:6798" }' +assert_output_json_eq '{"originalmsg": "ABCD:EF01:2345:6789:ABCD:EF01:2345:1:6798", "unparsed-data": ":6798" }' execute ':0:0:0:0:0:0:1' # missing first digit assert_output_json_eq '{ "originalmsg": ":0:0:0:0:0:0:1", "unparsed-data": ":0:0:0:0:0:0:1" }' diff --git a/tests/field_ipv6_jsoncnf.sh b/tests/field_ipv6_jsoncnf.sh index 3a75059a..f20d0384 100755 --- a/tests/field_ipv6_jsoncnf.sh +++ b/tests/field_ipv6_jsoncnf.sh @@ -41,7 +41,7 @@ execute 'ABCD:EF01:2345:6789:ABCD:EF01:2345::6789' # :: with too many blocks assert_output_json_eq '{ "originalmsg": "ABCD:EF01:2345:6789:ABCD:EF01:2345::6789", "unparsed-data": "ABCD:EF01:2345:6789:ABCD:EF01:2345::6789" }' execute 'ABCD:EF01:2345:6789:ABCD:EF01:2345:1:6798' # too many blocks (9) -assert_output_json_eq '{"originalmsg": "ABCD:EF01:2345:6789:ABCD:EF01:2345:1:6798", "unparsed-data": "ABCD:EF01:2345:6789:ABCD:EF01:2345:1:6798" }' +assert_output_json_eq '{"originalmsg": "ABCD:EF01:2345:6789:ABCD:EF01:2345:1:6798", "unparsed-data": ":6798" }' execute ':0:0:0:0:0:0:1' # missing first digit assert_output_json_eq '{ "originalmsg": ":0:0:0:0:0:0:1", "unparsed-data": ":0:0:0:0:0:0:1" }'