Skip to content
Myr

Parse no deeper than MAX_PARSING_DEPTH

Before adoption: this commit came in with the history the project adopted, so no landing records it.

while true; do printf '{"deeper": '; done | jq .

authored by W-Mark Kubacki · committed by Nico Williams · parent 83e2cf6 · Browse files · 1 file+6 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+6 added−0 removed

  • other:+6 added−0 removed

1 file+6 added−0 removed

modified:src/jv_parse.c+6 added
8 unmodified lines
9#include "jv_dtoa.h"1011typedef const char* presult;1213#ifndef MAX_PARSING_DEPTH14#define MAX_PARSING_DEPTH (256)15#endif1617#define TRY(x) do {presult msg__ = (x); if (msg__) return msg__; } while(0)18#ifdef __GNUC__19#define pfunc __attribute__((warn_unused_result)) presult20#else
129 unmodified lines
150151static pfunc parse_token(struct jv_parser* p, char ch) {152 switch (ch) {153 case '[':154 if (p->stackpos >= MAX_PARSING_DEPTH) return "Exceeds depth limit for parsing";155 if (jv_is_valid(p->next)) return "Expected separator between values";156 push(p, jv_array());157 break;158159 case '{':160 if (p->stackpos >= MAX_PARSING_DEPTH) return "Exceeds depth limit for parsing";161 if (jv_is_valid(p->next)) return "Expected separator between values";162 push(p, jv_object());163 break;164
694 unmodified lines