diff mbox series

[v1,1/1] helper: iplookuptable fix puting values to table

Message ID 1536674408-8395-2-git-send-email-odpbot@yandex.ru
State Superseded
Headers show
Series [v1,1/1] helper: iplookuptable fix puting values to table | expand

Commit Message

Github ODP bot Sept. 11, 2018, 2 p.m. UTC
From: Maxim Uvarov <maxim.uvarov@linaro.org>


On putting values to table we have to validate input data
and reject unaccepted data.

Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>

---
/** Email created from pull request 700 (Linaro:devel/master_iploopup)
 ** https://github.com/Linaro/odp/pull/700
 ** Patch: https://github.com/Linaro/odp/pull/700.patch
 ** Base sha: 33fbc04b6373960ec3f84de4e7e7b34c49d71508
 ** Merge commit sha: ce64f0400605ea7b3298769a1ebce6fa7da611a9
 **/
 helper/iplookuptable.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/helper/iplookuptable.c b/helper/iplookuptable.c
index 61f634022..b0141c311 100644
--- a/helper/iplookuptable.c
+++ b/helper/iplookuptable.c
@@ -585,24 +585,25 @@  prefix_insert_into_lx(
 		odph_iplookup_table_impl *tbl, prefix_entry_t *entry,
 		uint8_t cidr, odp_buffer_t nexthop, uint8_t level)
 {
-	uint8_t ret = 0;
+	int ret = 0;
 	uint32_t i = 0, limit = (1 << (level - cidr));
 	prefix_entry_t *e = entry, *ne = NULL;
 
 	for (i = 0; i < limit; i++, e++) {
-		if (e->child == 1) {
-			if (e->cidr > cidr)
-				continue;
+		if (e->cidr > cidr)
+			continue;
 
+		if (e->child == 1) {
 			e->cidr = cidr;
 			/* push to next level */
 			ne = (prefix_entry_t *)e->ptr;
 			ret = prefix_insert_into_lx(
 					tbl, ne, cidr, nexthop, cidr + 8);
+			if (ret == -1)
+				return -1;
+			if (ret == 0)
+				return ret;
 		} else {
-			if (e->cidr > cidr)
-				continue;
-
 			e->child = 0;
 			e->cidr = cidr;
 			e->nexthop = nexthop;
@@ -678,8 +679,9 @@  odph_iplookup_table_put_value(odph_table_t tbl, void *key, void *value)
 
 	nexthop = *((odp_buffer_t *)value);
 
-	if (prefix->cidr == 0)
+	if (prefix->cidr == 0 || prefix->cidr == 255)
 		return -1;
+
 	prefix->ip = prefix->ip & (0xffffffff << (IP_LENGTH - prefix->cidr));
 
 	/* insert into trie */