Skip to content

Commit

Permalink
fix json parse would always fail 2nd call
Browse files Browse the repository at this point in the history
  • Loading branch information
awick committed Oct 29, 2020
1 parent 0b0c4d2 commit 927ae53
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion capture/plugins/suricata.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,10 @@ LOCAL void suricata_process()
memset(out, 0, sizeof(out));
int rc;
if ((rc = js0n((unsigned char *)line, lineLen, out)) != 0) {
LOG("ERROR: Parse error %d >%.*s<\n", rc, lineLen, line);
if (rc > 0)
LOG("ERROR: Parse error at character pos %d (%c) >%.*s<\n", rc-1, line[rc-1], lineLen, line);
else
LOG("ERROR: Parse error %d >%.*s<\n", rc, lineLen, line);
fflush(stdout);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions capture/thirdparty/js0n.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int js0n(unsigned char *js, unsigned int len, unsigned int *out)
['"'] = &&l_unesc, ['\\'] = &&l_unesc, ['/'] = &&l_unesc, ['b'] = &&l_unesc,
['f'] = &&l_unesc, ['n'] = &&l_unesc, ['r'] = &&l_unesc, ['t'] = &&l_unesc, ['u'] = &&l_unesc
};
static void **go = gostruct;
void **go = gostruct;

for(cur=js,end=js+len; cur<end; cur++)
{
Expand All @@ -63,7 +63,7 @@ int js0n(unsigned char *js, unsigned int len, unsigned int *out)
return depth; // 0 if successful full parse, >0 for incomplete data

l_bad:
return 1;
return cur - js + 1;

l_up:
PUSH(0);
Expand Down

0 comments on commit 927ae53

Please sign in to comment.