From b1bcfb03685b6255c9b79ec48459eeb1e02ab485 Mon Sep 17 00:00:00 2001 From: Alice Frosi Date: Mon, 4 Sep 2023 10:17:52 +0200 Subject: cooker: fix tag check with the new format --- cooker/parse.c | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) (limited to 'cooker/parse.c') diff --git a/cooker/parse.c b/cooker/parse.c index 36c2649..5d5cab3 100644 --- a/cooker/parse.c +++ b/cooker/parse.c @@ -18,20 +18,42 @@ #include "emit.h" #include "util.h" +static bool get_valid_tag_field(const JSON_Object *obj, const char *field, + char *tag) +{ + JSON_Value *jvalue = json_object_get_value(obj, field); + JSON_Object *tmp; + + if (json_value_get_type(jvalue) != JSONObject) + return false; + if (!(tmp = json_object_get_object(obj, field))) + return false; + if (json_object_get_string(tmp, "set")) { + strcpy(tag, json_object_get_string(tmp, "set")); + return true; + } + if (json_object_get_string(tmp, "get")) { + strcpy(tag, json_object_get_string(tmp, "get")); + return true; + } + return NULL; +} + static void handle_fd(struct gluten_ctx *g, JSON_Value *value) { - JSON_Object *obj = json_value_get_object(value), *tmp; + JSON_Object *obj = json_value_get_object(value), *tmp = NULL; struct fd_desc desc = { .cloexec = 1 }; JSON_Value *jvalue; - const char *tag; + char tag[PATH_MAX]; debug(" Parsing \"fd\""); jvalue = json_object_get_value(obj, "src"); if (json_value_get_type(jvalue) == JSONObject) { - tmp = json_object_get_object(obj, "src"); - if (!tmp || !(tag = json_object_get_string(tmp, "tag"))) - die("invalid tag specification"); + if (!get_valid_tag_field(obj, "src", tag)) + die("invalid tag specification: %s", + json_serialize_to_string( + json_object_get_wrapping_value(tmp))); desc.srcfd = gluten_get_tag(g, tag); } else if (json_value_get_type(jvalue) == JSONNumber) { union value v = { .v_num = json_value_get_number(jvalue) }; @@ -45,8 +67,10 @@ static void handle_fd(struct gluten_ctx *g, JSON_Value *value) ; } else if (json_value_get_type(jvalue) == JSONObject) { tmp = json_object_get_object(obj, "new"); - if (!tmp || !(tag = json_object_get_string(tmp, "tag"))) - die("invalid tag specification"); + if (!get_valid_tag_field(obj, "new", tag)) + die("invalid tag specification: %s", + json_serialize_to_string( + json_object_get_wrapping_value(tmp))); desc.newfd = gluten_get_tag(g, tag); desc.setfd = 1; } else if (json_value_get_type(jvalue) == JSONNumber) { -- cgit v1.2.3