Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ucl_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ typedef SSIZE_T ssize_t;
*/

#define UCL_MAX_RECURSION 16
#define UCL_MAX_NESTING 1024
#define UCL_TRASH_KEY 0
#define UCL_TRASH_VALUE 1

Expand Down
12 changes: 12 additions & 0 deletions src/ucl_msgpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,18 @@ ucl_msgpack_get_container(struct ucl_parser *parser,
/*
* Insert new container to the stack
*/
unsigned int depth = 0;
struct ucl_stack *sp;
for (sp = parser->stack; sp != NULL; sp = sp->next) {
depth++;
}
if (depth >= UCL_MAX_NESTING) {
ucl_create_err(&parser->err,
"msgpack containers are nested too deep (over %d)",
UCL_MAX_NESTING);
return NULL;
}

if (parser->stack == NULL) {
parser->stack = calloc(1, sizeof(struct ucl_stack));

Expand Down
13 changes: 13 additions & 0 deletions src/ucl_sexp.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ bool ucl_parse_csexp(struct ucl_parser *parser)
ucl_object_t *obj;
struct ucl_stack *st;
uint64_t len = 0;
unsigned int depth = 0;
enum {
start_parse,
read_obrace,
Expand Down Expand Up @@ -95,6 +96,14 @@ bool ucl_parse_csexp(struct ucl_parser *parser)
break;

case read_obrace:
if (depth >= UCL_MAX_NESTING) {
ucl_create_err(&parser->err,
"csexp nesting too deep (over %d)",
UCL_MAX_NESTING);
state = parse_err;
continue;
}

st = calloc(1, sizeof(*st));

if (st == NULL) {
Expand Down Expand Up @@ -125,6 +134,7 @@ bool ucl_parse_csexp(struct ucl_parser *parser)
LL_PREPEND(parser->stack, st);
}

depth++;
p++;
NEXT_STATE;

Expand Down Expand Up @@ -217,6 +227,9 @@ bool ucl_parse_csexp(struct ucl_parser *parser)

free(st);
st = NULL;
if (depth > 0) {
depth--;
}
p++;
NEXT_STATE;
break;
Expand Down
Loading