From 5d592ce6c4596b25d5779a224d03c096bc25db54 Mon Sep 17 00:00:00 2001
From: Phil Sutter <phil@nwl.cc>
Date: Fri, 22 Jun 2018 14:18:58 +0200
Subject: expr/data_reg: Fix JSON parsing on big endian

Since reg->len is a 32bit variable, one needs to pass NFTNL_TYPE_U32 to
nftnl_jansson_parse_val(). Otherwise, only the most significant byte in
that variable is being written to.

Since the value could potentially be larger than 255, increase node_name
buffer to avoid a compiler warning.

Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 src/expr/data_reg.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/expr/data_reg.c b/src/expr/data_reg.c
index 1b28b29..ad7f4cb 100644
--- a/src/expr/data_reg.c
+++ b/src/expr/data_reg.c
@@ -59,10 +59,10 @@ static int nftnl_data_reg_verdict_json_parse(union nftnl_data_reg *reg, json_t *
 static int nftnl_data_reg_value_json_parse(union nftnl_data_reg *reg, json_t *data,
 					 struct nftnl_parse_err *err)
 {
-	char node_name[8] = {};	/* strlen("data256") + 1 == 8 */
+	char node_name[32] = {};
 	int ret, remain = sizeof(node_name), offset = 0, i;
 
-	if (nftnl_jansson_parse_val(data, "len", NFTNL_TYPE_U8, &reg->len, err) < 0)
+	if (nftnl_jansson_parse_val(data, "len", NFTNL_TYPE_U32, &reg->len, err) < 0)
 			return DATA_NONE;
 
 	for (i = 0; i < div_round_up(reg->len, sizeof(uint32_t)); i++) {
-- 
cgit v1.2.1

