Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Checkpoint parser #325

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -2936,19 +2936,39 @@ PARSER_Parse(CheckpointLEA)
if(i+1 >= npb->strLen || npb->str[i] != ':') {
FAIL(LN_WRONGPARSER);
}
/* Sometimes there is multiple colons */
while( i < npb->strLen && npb->str[i+1] == ':' ) {
i++;
}
lenName = i - iName;
++i; /* skip ':' */

while(i < npb->strLen && npb->str[i] == ' ') /* skip leading SP */
++i;
iValue = i;
while(i < npb->strLen && npb->str[i] != ';') {
/* Improvement by KGuillemot & M4jr0 to support quoted values */
if( npb->str[i] == '"' ) {
iValue = i+1;
i++;
while( i < npb->strLen && ( npb->str[i] != '"' || npb->str[i-1] == '\\' ) ) {
++i;
}
// Do not take the " in value
lenValue = i - iValue;
// Skip "
++i;
} else {
iValue = i;
while (i < npb->strLen && npb->str[i] != ';' && npb->str[i] != data->terminator) {
++i;
}
lenValue = i - iValue;
}
if(i+1 > npb->strLen || npb->str[i] != ';')

if(i+1 > npb->strLen || (npb->str[i] != ';' && npb->str[i] != data->terminator))
FAIL(LN_WRONGPARSER);
lenValue = i - iValue;
++i; /* skip ';' */

if(npb->str[i] == ';')
++i; /* skip ';' */

if(value != NULL) {
CHKN(name = malloc(sizeof(char) * (lenName + 1)));
Expand Down
3 changes: 3 additions & 0 deletions tests/field_checkpoint-lea-terminator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ add_rule 'rule=:[ %{"name":"f", "type":"checkpoint-lea", "terminator": "]"}%]'
execute '[ tcp_flags: RST-ACK; src: 192.168.0.1; ]'
assert_output_json_eq '{ "f": { "tcp_flags": "RST-ACK", "src": "192.168.0.1" } }'

# Newest Checkpoint format
execute '[ tcp_flags:"RST-ACK"; src:"192.168.0.1"; ]'
assert_output_json_eq '{ "f": { "tcp_flags": "RST-ACK", "src": "192.168.0.1" } }'

cleanup_tmp_files

3 changes: 3 additions & 0 deletions tests/field_checkpoint-lea_jsoncnf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ add_rule 'rule=:%{"name":"f", "type":"checkpoint-lea"}%'
execute 'tcp_flags: RST-ACK; src: 192.168.0.1;'
assert_output_json_eq '{ "f": { "tcp_flags": "RST-ACK", "src": "192.168.0.1" } }'

# Newest Checkpoint format
execute 'tcp_flags:"RST-ACK"; src:"192.168.0.1";'
assert_output_json_eq '{ "f": { "tcp_flags": "RST-ACK", "src": "192.168.0.1" } }'

cleanup_tmp_files

3 changes: 3 additions & 0 deletions tests/field_checkpoint-lea_v1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ add_rule 'rule=:%f:checkpoint-lea%'
execute 'tcp_flags: RST-ACK; src: 192.168.0.1;'
assert_output_json_eq '{ "f": { "tcp_flags": "RST-ACK", "src": "192.168.0.1" } }'

# Newest Checkpoint format
execute 'tcp_flags:"RST-ACK"; src:"192.168.0.1";'
assert_output_json_eq '{ "f": { "tcp_flags": "RST-ACK", "src": "192.168.0.1" } }'

cleanup_tmp_files