diff options
author | juhosg <juhosg@3c298f89-4303-0410-b956-a3cf2f4a3e73> | 2011-01-08 17:30:33 +0000 |
---|---|---|
committer | juhosg <juhosg@3c298f89-4303-0410-b956-a3cf2f4a3e73> | 2011-01-08 17:30:33 +0000 |
commit | 69e8309e23b96176a74c356e47c48bac610bdda1 (patch) | |
tree | edcb5313987862ad66de258111cf9e43a962193c /package/swconfig/src/swlib.c | |
parent | af8ba321fb7a77c471b8aae28cb196b611c3a031 (diff) |
package/swconfig: add sanity checks to prevent a segfault
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@24932 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'package/swconfig/src/swlib.c')
-rw-r--r-- | package/swconfig/src/swlib.c | 15 |
1 files changed, 15 insertions, 0 deletions
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) |