package/swconfig: add sanity checks to prevent a segfault

SVN-Revision: 24932
This commit is contained in:
Gabor Juhos 2011-01-08 17:30:33 +00:00
parent ebbd3311e1
commit 9a32655293
2 changed files with 16 additions and 1 deletions

View file

@ -8,7 +8,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=swconfig PKG_NAME:=swconfig
PKG_RELEASE:=6 PKG_RELEASE:=7
include $(INCLUDE_DIR)/package.mk include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/kernel.mk include $(INCLUDE_DIR)/kernel.mk

View file

@ -368,11 +368,26 @@ int swlib_set_attr_string(struct switch_dev *dev, struct switch_attr *a, int por
ptr = (char *)str; ptr = (char *)str;
while(ptr && *ptr) 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].flags = 0;
ports[val.len].id = strtoul(ptr, &ptr, 10); ports[val.len].id = strtoul(ptr, &ptr, 10);
while(*ptr && !isspace(*ptr)) { while(*ptr && !isspace(*ptr)) {
if (*ptr == 't') if (*ptr == 't')
ports[val.len].flags |= SWLIB_PORT_FLAG_TAGGED; ports[val.len].flags |= SWLIB_PORT_FLAG_TAGGED;
else
return -1;
ptr++; ptr++;
} }
if (*ptr) if (*ptr)