diff options
author | Gabor Juhos <juhosg@openwrt.org> | 2011-01-08 17:30:33 +0000 |
---|---|---|
committer | Gabor Juhos <juhosg@openwrt.org> | 2011-01-08 17:30:33 +0000 |
commit | 9a32655293fbdaf8ed4172f15746bc9cf3704133 (patch) | |
tree | 718a56e922328dd3c3ae08cd697304d77dafccea /package/swconfig/src/swlib.c | |
parent | ebbd3311e1054b0fcf8279e519746e71a0de46b4 (diff) | |
download | upstream-9a32655293fbdaf8ed4172f15746bc9cf3704133.tar.gz upstream-9a32655293fbdaf8ed4172f15746bc9cf3704133.tar.bz2 upstream-9a32655293fbdaf8ed4172f15746bc9cf3704133.zip |
package/swconfig: add sanity checks to prevent a segfault
SVN-Revision: 24932
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) |