From 9a32655293fbdaf8ed4172f15746bc9cf3704133 Mon Sep 17 00:00:00 2001
From: Gabor Juhos <juhosg@openwrt.org>
Date: Sat, 8 Jan 2011 17:30:33 +0000
Subject: [PATCH] package/swconfig: add sanity checks to prevent a segfault

SVN-Revision: 24932
---
 package/swconfig/Makefile    |  2 +-
 package/swconfig/src/swlib.c | 15 +++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/package/swconfig/Makefile b/package/swconfig/Makefile
index 24ebaee456..363b3a01fd 100644
--- a/package/swconfig/Makefile
+++ b/package/swconfig/Makefile
@@ -8,7 +8,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=swconfig
-PKG_RELEASE:=6
+PKG_RELEASE:=7
 
 include $(INCLUDE_DIR)/package.mk
 include $(INCLUDE_DIR)/kernel.mk
diff --git a/package/swconfig/src/swlib.c b/package/swconfig/src/swlib.c
index 59456a33d9..c2316d0686 100644
--- a/package/swconfig/src/swlib.c
+++ b/package/swconfig/src/swlib.c
@@ -368,11 +368,26 @@ int swlib_set_attr_string(struct switch_dev *dev, struct switch_attr *a, int por
 		ptr = (char *)str;
 		while(ptr && *ptr)
 		{
+			while(*ptr && isspace(*ptr))
+				ptr++;
+
+			if (!*ptr)
+				break;
+
+			if (!isdigit(*ptr))
+				return -1;
+
+			if (val.len >= dev->ports)
+				return -1;
+
 			ports[val.len].flags = 0;
 			ports[val.len].id = strtoul(ptr, &ptr, 10);
 			while(*ptr && !isspace(*ptr)) {
 				if (*ptr == 't')
 					ports[val.len].flags |= SWLIB_PORT_FLAG_TAGGED;
+				else
+					return -1;
+
 				ptr++;
 			}
 			if (*ptr)
-- 
2.30.2