sharkd: check if JSON value is string or primitive (true/false/null/number).

Add extra check for token type, previously it was possible to pass for example:
{"columns":["one","two","three"]}. Such format is not supported.

Change-Id: I6ac2e3ca9eba868cd72ed886ad40745ebbc43d73
Reviewed-on: https://code.wireshark.org/review/23834
Petri-Dish: Jakub Zawadzki <darkjames-ws@darkjames.pl>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
This commit is contained in:
Jakub Zawadzki 2017-10-04 08:12:23 +02:00 committed by Michael Mann
parent ea6e4b577f
commit 1961297a55
1 changed files with 8 additions and 2 deletions

View File

@ -3861,13 +3861,19 @@ sharkd_session_process(char *buf, const jsmntok_t *tokens, int count)
return;
}
if (tokens[i + 1].type != JSMN_STRING && tokens[i + 1].type != JSMN_PRIMITIVE)
{
fprintf(stderr, "sanity check(3a): [%d] wrong type\n", i + 1);
return;
}
buf[tokens[i + 0].end] = '\0';
buf[tokens[i + 1].end] = '\0';
/* unescape only value, as keys are simple strings */
if (!json_unescape_str(&buf[tokens[i + 1].start]))
if (tokens[i + 1].type == JSMN_STRING && !json_unescape_str(&buf[tokens[i + 1].start]))
{
fprintf(stderr, "sanity check(3a): [%d] cannot unescape string\n", i + 1);
fprintf(stderr, "sanity check(3b): [%d] cannot unescape string\n", i + 1);
return;
}
}