[libnftnl PATCH] lookup: Fix an invalid read

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Valgrind reports the following invalid read:

$ sudo valgrind ./nft-parsing-test -f ../jsonfiles/30-rule-lookup.json
==26664== Memcheck, a memory error detector
==26664== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==26664== Using Valgrind-3.9.0 and LibVEX; rerun with -h for copyright info
==26664== Command: ./nft-parsing-test -f ../jsonfiles/30-rule-lookup.json
==26664==
==26664== Invalid read of size 8
==26664==    at 0x4E45490: nft_rule_expr_lookup_set (lookup.c:50)
==26664==    by 0x4E40B04: nft_rule_expr_set (expr.c:73)
==26664==    by 0x4E44FFF: nft_rule_expr_lookup_json_parse (lookup.c:157)
==26664==    by 0x4E408CD: nft_jansson_expr_parse (jansson.c:206)
==26664==    by 0x4E3B719: nft_jansson_parse_rule (rule.c:606)
==26664==    by 0x4E3F005: nft_ruleset_do_parse (ruleset.c:312)
==26664==    by 0x401479: test_json (nft-parsing-test.c:129)
==26664==    by 0x4017C2: execute_test_file (nft-parsing-test.c:270)
==26664==    by 0x400EBB: main (nft-parsing-test.c:332)
==26664==  Address 0x5c34d40 is 0 bytes inside a block of size 5 alloc'd
==26664==    at 0x4C274A0: malloc (vg_replace_malloc.c:291)
==26664==    by 0x56834FF: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5685825: json_string_nocheck (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5682A3F: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5682C5D: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5682C5D: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5682EDD: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5683295: json_loadf (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==
==26664== Invalid read of size 8
==26664==    at 0x4E45497: nft_rule_expr_lookup_set (lookup.c:50)
==26664==    by 0x4E40B04: nft_rule_expr_set (expr.c:73)
==26664==    by 0x4E44FFF: nft_rule_expr_lookup_json_parse (lookup.c:157)
==26664==    by 0x4E408CD: nft_jansson_expr_parse (jansson.c:206)
==26664==    by 0x4E3B719: nft_jansson_parse_rule (rule.c:606)
==26664==    by 0x4E3F005: nft_ruleset_do_parse (ruleset.c:312)
==26664==    by 0x401479: test_json (nft-parsing-test.c:129)
==26664==    by 0x4017C2: execute_test_file (nft-parsing-test.c:270)
==26664==    by 0x400EBB: main (nft-parsing-test.c:332)
==26664==  Address 0x5c34d48 is 3 bytes after a block of size 5 alloc'd
==26664==    at 0x4C274A0: malloc (vg_replace_malloc.c:291)
==26664==    by 0x56834FF: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5685825: json_string_nocheck (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5682A3F: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5682C5D: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5682C5D: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5682EDD: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5683295: json_loadf (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)

Signed-off-by: Ana Rey <anarey@xxxxxxxxx>
---
 src/expr/lookup.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/expr/lookup.c b/src/expr/lookup.c
index 5e0bf75..50282a8 100644
--- a/src/expr/lookup.c
+++ b/src/expr/lookup.c
@@ -47,8 +47,8 @@ nft_rule_expr_lookup_set(struct nft_rule_expr *e, uint16_t type,
 		lookup->dreg = *((uint32_t *)data);
 		break;
 	case NFT_EXPR_LOOKUP_SET:
-		memcpy(lookup->set_name, data, IFNAMSIZ);
-		lookup->set_name[IFNAMSIZ-1] = '\0';
+		snprintf(lookup->set_name, sizeof(lookup->set_name), "%s",
+			 (const char *)data);
 		break;
 	default:
 		return -1;
-- 
1.9.0

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux