Skip to content

Commit

Permalink
Bugfix for strict primitive parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
dominickpastore committed May 26, 2020
1 parent 30f2b7c commit fd2e0e4
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions jsmn.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,26 +315,34 @@ static int jsmn_parse_primitive(jsmn_parser *parser, const char *js,
numstate != JSMN_NUM_INT_ZERO &&
numstate != JSMN_NUM_FRAC &&
numstate != JSMN_NUM_EXP) {
return JSMN_ERROR_INVAL;
if (parser->pos >= len || js[parser->pos] == '\0') {
parser->pos = start;
return JSMN_ERROR_PART;
} else {
return JSMN_ERROR_INVAL;
}
}
}

/* Verify that what comes after the primitive is a non-primitive character */
switch (js[parser->pos]) {
case '\t':
case '\r':
case '\n':
case ' ':
case ',':
case ':':
case '"':
case '[':
case ']':
case '{':
case '}':
break;
default:
return JSMN_ERROR_INVAL;
if (parser->pos < len) {
switch (js[parser->pos]) {
case '\t':
case '\r':
case '\n':
case ' ':
case ',':
case ':':
case '"':
case '[':
case ']':
case '{':
case '}':
case '\0':
break;
default:
return JSMN_ERROR_INVAL;
}
}
#else
for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
Expand Down Expand Up @@ -387,12 +395,11 @@ static int jsmn_parse_string(jsmn_parser *parser, const char *js,
const size_t len, jsmntok_t *tokens,
const size_t num_tokens) {
jsmntok_t *token;

unsigned int start = parser->pos;

/* Skip starting quote */
parser->pos++;

/* Skip starting quote */
for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
char c = js[parser->pos];

Expand Down

0 comments on commit fd2e0e4

Please sign in to comment.