Skip to content

Commit

Permalink
fix issue #45 by preventing buffer overrun
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Nunberg committed Apr 1, 2021
1 parent 684b60f commit 7ab43c2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions jsonsl.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,20 @@ jsonsl_feed(jsonsl_t jsn, const jsonsl_char_t *bytes, size_t nbytes)
INVOKE_ERROR(HKEY_EXPECTED); \
}

/**
* The VERIFY_SPECIAL appends a ',' to the literal string in order
* to prevent a buffer overflow. It is actually not possible for CUR_CHAR
* to match a ',' -- as this is part of the is_special_end() set of
* characters.
*/

#define VERIFY_SPECIAL(lit) \
if (CUR_CHAR != (lit)[jsn->pos - state->pos_begin]) { \
if (CUR_CHAR != (lit",")[jsn->pos - state->pos_begin]) { \
INVOKE_ERROR(SPECIAL_EXPECTED); \
}

#define VERIFY_SPECIAL_CI(lit) \
if (tolower(CUR_CHAR) != (lit)[jsn->pos - state->pos_begin]) { \
if (tolower(CUR_CHAR) != (lit",")[jsn->pos - state->pos_begin]) { \
INVOKE_ERROR(SPECIAL_EXPECTED); \
}

Expand Down

0 comments on commit 7ab43c2

Please sign in to comment.