[BusyBox-cvs] CVS update of busybox/libbb (interface.c)
Erik Andersen
andersen at codepoet.org
Thu Aug 12 16:52:01 UTC 2004
Date: Thursday, August 12, 2004 @ 10:52:01
Author: andersen
Path: /var/cvs/busybox/libbb
Modified: interface.c (1.23 -> 1.24)
Patch from solar to fix problems with get_name()
Index: busybox/libbb/interface.c
diff -u busybox/libbb/interface.c:1.23 busybox/libbb/interface.c:1.24
--- busybox/libbb/interface.c:1.23 Thu Jul 22 19:49:46 2004
+++ busybox/libbb/interface.c Thu Aug 12 10:52:00 2004
@@ -986,31 +986,36 @@
return err;
}
-static char *get_name(char *name, char *p)
+char *get_name(char *name, char *p)
{
- while (isspace(*p))
- p++;
- while (*p) {
- if (isspace(*p))
- break;
- if (*p == ':') { /* could be an alias */
- char *dot = p, *dotname = name;
-
- *name++ = *p++;
- while (isdigit(*p))
- *name++ = *p++;
- if (*p != ':') { /* it wasn't, backup */
- p = dot;
- name = dotname;
- }
- if (*p == '\0')
- return NULL;
- p++;
- break;
+ /* Extract <name>[:<alias>] from nul-terminated p where p matches
+ <name>[:<alias>]: after leading whitespace.
+ If match is not made, set name empty and return unchanged p */
+ int namestart=0, nameend=0, aliasend;
+ while (isspace(p[namestart]))
+ namestart++;
+ nameend=namestart;
+ while (p[nameend] && p[nameend]!=':' && !isspace(p[nameend]))
+ nameend++;
+ if (p[nameend]==':') {
+ aliasend=nameend+1;
+ while (p[aliasend] && isdigit(p[aliasend]))
+ aliasend++;
+ if (p[aliasend]==':') {
+ nameend=aliasend;
}
- *name++ = *p++;
+ if ((nameend-namestart)<IFNAMSIZ) {
+ memcpy(name,&p[namestart],nameend-namestart);
+ name[nameend-namestart]='\0';
+ p=&p[nameend];
+ } else {
+ /* Interface name too large */
+ name[0]='\0';
+ }
+ } else {
+ /* first ':' not found - return empty */
+ name[0]='\0';
}
- *name++ = '\0';
return p;
}
More information about the busybox-cvs
mailing list