aboutgitcodelistschat:MatrixIRC
diff options
context:
space:
mode:
authorAlice Frosi <afrosi@redhat.com>2023-09-04 10:17:52 +0200
committerAlice Frosi <afrosi@redhat.com>2023-09-04 10:17:52 +0200
commitb1bcfb03685b6255c9b79ec48459eeb1e02ab485 (patch)
treebfe45dd74f34cd7fc0e7ded6b9abef64e1845c9a
parent508b2b2f1473b67d41d947a92c368765cb868e17 (diff)
downloadseitan-b1bcfb03685b6255c9b79ec48459eeb1e02ab485.tar
seitan-b1bcfb03685b6255c9b79ec48459eeb1e02ab485.tar.gz
seitan-b1bcfb03685b6255c9b79ec48459eeb1e02ab485.tar.bz2
seitan-b1bcfb03685b6255c9b79ec48459eeb1e02ab485.tar.lz
seitan-b1bcfb03685b6255c9b79ec48459eeb1e02ab485.tar.xz
seitan-b1bcfb03685b6255c9b79ec48459eeb1e02ab485.tar.zst
seitan-b1bcfb03685b6255c9b79ec48459eeb1e02ab485.zip
cooker: fix tag check with the new format
-rw-r--r--cooker/parse.c38
1 files changed, 31 insertions, 7 deletions
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) {