Skip to content

Commit

Permalink
Made ipv6 behave more like ipv4 (Doesn't have to end in space)
Browse files Browse the repository at this point in the history
Fixed null ptr deref
  • Loading branch information
Kenneth Shelton authored and julthomas committed Nov 25, 2017
1 parent 6f694b9 commit 192fa5a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/field_ipv6.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" }'
Expand Down
2 changes: 1 addition & 1 deletion tests/field_ipv6_jsoncnf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" }'
Expand Down

0 comments on commit 192fa5a

Please sign in to comment.