summaryrefslogtreecommitdiffstats
path: root/src/parser_json.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser_json.c')
-rw-r--r--src/parser_json.c41
1 files changed, 30 insertions, 11 deletions
diff --git a/src/parser_json.c b/src/parser_json.c
index bd865de5..be0de698 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -1286,11 +1286,18 @@ static struct expr *json_parse_binop_expr(struct json_ctx *ctx,
static struct expr *json_check_concat_expr(struct json_ctx *ctx, struct expr *e)
{
+ if (e->etype != EXPR_CONCAT) {
+ json_error(ctx, "Expected concatenation, got %s", expr_name(e));
+ goto err_free;
+ }
+
if (expr_concat(e)->size >= 2)
return e;
json_error(ctx, "Concatenation with %d elements is illegal",
expr_concat(e)->size);
+
+err_free:
expr_free(e);
return NULL;
}
@@ -2952,6 +2959,25 @@ static struct expr *parse_policy(const char *policy)
sizeof(int) * BITS_PER_BYTE, &policy_num);
}
+static struct expr *ifname_expr_alloc(struct json_ctx *ctx,
+ const char *name)
+{
+ size_t length = strlen(name);
+
+ if (length == 0) {
+ json_error(ctx, "empty interface name");
+ return NULL;
+ }
+
+ if (length >= IFNAMSIZ) {
+ json_error(ctx, "Device name %s too long", name);
+ return NULL;
+ }
+
+ return constant_expr_alloc(int_loc, &ifname_type, BYTEORDER_HOST_ENDIAN,
+ length * BITS_PER_BYTE, name);
+}
+
static struct expr *json_parse_devs(struct json_ctx *ctx, json_t *root)
{
struct expr *tmp, *expr = compound_expr_alloc(int_loc, EXPR_LIST);
@@ -2960,15 +2986,12 @@ static struct expr *json_parse_devs(struct json_ctx *ctx, json_t *root)
size_t index;
if (!json_unpack(root, "s", &dev)) {
- if (strlen(dev) >= IFNAMSIZ) {
- json_error(ctx, "Device name %s too long", dev);
+ tmp = ifname_expr_alloc(ctx, dev);
+ if (!tmp) {
expr_free(expr);
return NULL;
}
- tmp = constant_expr_alloc(int_loc, &ifname_type,
- BYTEORDER_HOST_ENDIAN,
- strlen(dev) * BITS_PER_BYTE, dev);
compound_expr_add(expr, tmp);
return expr;
}
@@ -2985,15 +3008,11 @@ static struct expr *json_parse_devs(struct json_ctx *ctx, json_t *root)
return NULL;
}
- if (strlen(dev) >= IFNAMSIZ) {
- json_error(ctx, "Device name %s too long at index %zu", dev, index);
+ tmp = ifname_expr_alloc(ctx, dev);
+ if (!tmp) {
expr_free(expr);
return NULL;
}
-
- tmp = constant_expr_alloc(int_loc, &ifname_type,
- BYTEORDER_HOST_ENDIAN,
- strlen(dev) * BITS_PER_BYTE, dev);
compound_expr_add(expr, tmp);
}
return expr;