summaryrefslogtreecommitdiffstats
path: root/src/parser_json.c
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2018-05-28 18:51:01 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2018-06-01 09:16:48 +0200
commit25ccb4587de81e1b348e4e2f5404e70097ea8ec9 (patch)
tree7a03f4c44a777feecedac089c7203c4591cb6381 /src/parser_json.c
parent1c01c8e24e749e7f61b3cd1f4cf4ca8dc32ffd65 (diff)
JSON: Review set elem expressions
* There is no need to prefix element-specific properties with 'elem_', they can't conflict. * In json_parse_set_stmt(), searching for above properties is pointless since that's already done by called function. * Fix potential NULL-pointer deref in json_parse_set_elem_expr_stmt(): json_parse_flagged_expr() may return NULL. Signed-off-by: Phil Sutter <phil@nwl.cc> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/parser_json.c')
-rw-r--r--src/parser_json.c15
1 files changed, 4 insertions, 11 deletions
diff --git a/src/parser_json.c b/src/parser_json.c
index afcd10a3..fd60c59c 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -1140,11 +1140,11 @@ static struct expr *json_parse_set_elem_expr(struct json_ctx *ctx,
expr = set_elem_expr_alloc(int_loc, expr);
- if (!json_unpack(root, "{s:i}", "elem_timeout", &i))
+ if (!json_unpack(root, "{s:i}", "timeout", &i))
expr->timeout = i * 1000;
- if (!json_unpack(root, "{s:i}", "elem_expires", &i))
+ if (!json_unpack(root, "{s:i}", "expires", &i))
expr->expiration = i * 1000;
- if (!json_unpack(root, "{s:s}", "elem_comment", &expr->comment))
+ if (!json_unpack(root, "{s:s}", "comment", &expr->comment))
expr->comment = xstrdup(expr->comment);
return expr;
@@ -1298,7 +1298,7 @@ static struct expr *json_parse_set_elem_expr_stmt(struct json_ctx *ctx, json_t *
{
struct expr *expr = json_parse_flagged_expr(ctx, CTX_F_SES, root);
- if (expr->ops->type != EXPR_SET_ELEM)
+ if (expr && expr->ops->type != EXPR_SET_ELEM)
expr = set_elem_expr_alloc(int_loc, expr);
return expr;
@@ -1820,7 +1820,6 @@ static struct stmt *json_parse_set_stmt(struct json_ctx *ctx,
struct expr *expr, *expr2;
struct stmt *stmt;
json_t *elem;
- uint64_t tmp;
int op;
if (json_unpack_err(ctx, value, "{s:s, s:o, s:s}",
@@ -1842,12 +1841,6 @@ static struct stmt *json_parse_set_stmt(struct json_ctx *ctx,
return NULL;
}
- if (!json_unpack(elem, "{s:I}", "elem_timeout", &tmp))
- expr->timeout = tmp * 1000;
- if (!json_unpack(elem, "{s:I}", "elem_expires", &tmp))
- expr->expiration = tmp * 1000;
- json_unpack(elem, "{s:s}", "elem_comment", &expr->comment);
-
if (set[0] != '@') {
json_error(ctx, "Illegal set reference in set statement.");
expr_free(expr);