[PATCH 08/11] net: string_to_ip: add sanity check for > 255

Wolfram Sang w.sang at pengutronix.de
Sun Sep 25 16:54:11 EDT 2011


Signed-off-by: Wolfram Sang <w.sang at pengutronix.de>
---
 net/net.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/net/net.c b/net/net.c
index f1ab667..3578118 100644
--- a/net/net.c
+++ b/net/net.c
@@ -113,8 +113,10 @@ int string_to_ip(const char *s, IPaddr_t *ip)
 			return -EINVAL;
 
 		val = simple_strtoul(s, &e, 10);
-		addr <<= 8;
-		addr |= (val & 0xFF);
+		if (val > 255)
+			return -EINVAL;
+
+		addr = (addr << 8) | val;
 
 		if (*e != '.' && i != 3)
 			return -EINVAL;
-- 
1.7.5.4




More information about the barebox mailing list