json: unify json_parse depth to MAX_JSON_DEPTH=50

This commit is contained in:
cvzi 2023-07-08 01:51:21 +02:00 committed by sfan5
parent 2e7fcc5a2a
commit f5eb7ea1a9
4 changed files with 5 additions and 5 deletions

View File

@ -126,7 +126,7 @@ static char *json_execute_command(struct mpv_handle *client, void *ta_parent,
bool async = false;
bool send_reply = true;
rc = json_parse(ta_parent, &msg_node, &src, 50);
rc = json_parse(ta_parent, &msg_node, &src, MAX_JSON_DEPTH);
if (rc < 0) {
mp_err(log, "malformed JSON received: '%s'\n", src);
rc = MPV_ERROR_INVALID_PARAMETER;

View File

@ -21,6 +21,8 @@
// We reuse mpv_node.
#include "libmpv/client.h"
#define MAX_JSON_DEPTH 50
int json_parse(void *ta_parent, struct mpv_node *dst, char **src, int max_depth);
void json_skip_whitespace(char **src);
int json_write(char **s, struct mpv_node *src);

View File

@ -1163,7 +1163,7 @@ static int script_parse_json(lua_State *L, void *tmp)
bool trail = lua_toboolean(L, 2);
bool ok = false;
struct mpv_node node;
if (json_parse(tmp, &node, &text, 32) >= 0) {
if (json_parse(tmp, &node, &text, MAX_JSON_DEPTH) >= 0) {
json_skip_whitespace(&text);
ok = !text[0] || trail;
}

View File

@ -63,8 +63,6 @@ static const struct entry entries[] = {
NODE_MAP(L("_a12"), L(NODE_STR("b")))},
};
#define MAX_DEPTH 10
int main(void)
{
for (int n = 0; n < MP_ARRAY_SIZE(entries); n++) {
@ -73,7 +71,7 @@ int main(void)
char *s = talloc_strdup(tmp, e->src);
json_skip_whitespace(&s);
struct mpv_node res;
bool ok = json_parse(tmp, &res, &s, MAX_DEPTH) >= 0;
bool ok = json_parse(tmp, &res, &s, MAX_JSON_DEPTH) >= 0;
assert_true(ok != e->expect_fail);
if (!ok) {
talloc_free(tmp);