Skip to content

Commit 1e18f60

Browse files
authored
Merge pull request #351 from VultureProject/fix_cef_upstream
FIX CEF PARSER
2 parents 28be845 + 6e6a50b commit 1e18f60

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

src/parser.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2775,7 +2775,8 @@ cefParseExtensionValue(npb_t *const npb,
27752775
if(npb->str[i] != '=' &&
27762776
npb->str[i] != '\\' &&
27772777
npb->str[i] != 'r' &&
2778-
npb->str[i] != 'n')
2778+
npb->str[i] != 'n' &&
2779+
npb->str[i] != '/')
27792780
FAIL(LN_WRONGPARSER);
27802781
inEscape = 0;
27812782
} else {
@@ -2852,16 +2853,22 @@ cefParseExtensions(npb_t *const npb,
28522853
++i;
28532854
iName = i;
28542855
CHKR(cefParseName(npb, &i));
2855-
if(i+1 >= npb->strLen || npb->str[i] != '=')
2856+
2857+
if(npb->str[i] != '=')
28562858
FAIL(LN_WRONGPARSER);
28572859
lenName = i - iName;
2858-
++i; /* skip '=' */
2860+
2861+
/* Init if the last value is empty */
2862+
lenValue = 0;
2863+
if(i < npb->strLen){
2864+
++i; /* skip '=' */
28592865

2860-
iValue = i;
2861-
CHKR(cefParseExtensionValue(npb, &i));
2862-
lenValue = i - iValue;
2866+
iValue = i;
2867+
CHKR(cefParseExtensionValue(npb, &i));
2868+
lenValue = i - iValue;
28632869

2864-
++i; /* skip past value */
2870+
++i; /* skip past value */
2871+
}
28652872

28662873
if(jroot != NULL) {
28672874
CHKN(name = malloc(sizeof(char) * (lenName + 1)));
@@ -2882,6 +2889,8 @@ cefParseExtensions(npb_t *const npb,
28822889
break;
28832890
case '\\': value[iDst] = '\\';
28842891
break;
2892+
case '/': value[iDst] = '/';
2893+
break;
28852894
default: break;
28862895
}
28872896
} else {
@@ -2989,7 +2998,9 @@ PARSER_Parse(CEF)
29892998
CHKR(cefGetHdrField(npb, &i, (value == NULL) ? NULL : &sigID));
29902999
CHKR(cefGetHdrField(npb, &i, (value == NULL) ? NULL : &name));
29913000
CHKR(cefGetHdrField(npb, &i, (value == NULL) ? NULL : &severity));
2992-
++i; /* skip over terminal '|' */
3001+
3002+
while(i < npb->strLen && npb->str[i] == ' ') /* skip leading SP */
3003+
++i;
29933004

29943005
/* OK, we now know we have a good header. Now, we need
29953006
* to process extensions.

tests/field_cef.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ execute 'CEF:0|Vendor|Product|Version|Signature ID|some name|Severity| ' # singl
3939
assert_output_json_eq '{ "f": { "DeviceVendor": "Vendor", "DeviceProduct": "Product", "DeviceVersion": "Version", "SignatureID": "Signature ID", "Name": "some name", "Severity": "Severity", "Extensions": { } } }'
4040

4141
execute 'CEF:0|Vendor|Product|Version|Signature ID|some name|Severity| ' # multiple trailing spaces - invalid
42-
assert_output_json_eq '{ "originalmsg": "CEF:0|Vendor|Product|Version|Signature ID|some name|Severity| ", "unparsed-data": "CEF:0|Vendor|Product|Version|Signature ID|some name|Severity| " }'
42+
assert_output_json_eq '{ "f": { "DeviceVendor": "Vendor", "DeviceProduct": "Product", "DeviceVersion": "Version", "SignatureID": "Signature ID", "Name": "some name", "Severity": "Severity", "Extensions": { } } }'
4343

4444
execute 'CEF:0|Vendor'
4545
assert_output_json_eq '{ "originalmsg": "CEF:0|Vendor", "unparsed-data": "CEF:0|Vendor" }'

tests/field_cef_jsoncnf.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ execute 'CEF:0|Vendor|Product|Version|Signature ID|some name|Severity| ' # singl
3939
assert_output_json_eq '{ "f": { "DeviceVendor": "Vendor", "DeviceProduct": "Product", "DeviceVersion": "Version", "SignatureID": "Signature ID", "Name": "some name", "Severity": "Severity", "Extensions": { } } }'
4040

4141
execute 'CEF:0|Vendor|Product|Version|Signature ID|some name|Severity| ' # multiple trailing spaces - invalid
42-
assert_output_json_eq '{ "originalmsg": "CEF:0|Vendor|Product|Version|Signature ID|some name|Severity| ", "unparsed-data": "CEF:0|Vendor|Product|Version|Signature ID|some name|Severity| " }'
42+
assert_output_json_eq '{ "f": { "DeviceVendor": "Vendor", "DeviceProduct": "Product", "DeviceVersion": "Version", "SignatureID": "Signature ID", "Name": "some name", "Severity": "Severity", "Extensions": { } } }'
4343

4444
execute 'CEF:0|Vendor'
4545
assert_output_json_eq '{ "originalmsg": "CEF:0|Vendor", "unparsed-data": "CEF:0|Vendor" }'

0 commit comments

Comments
 (0)