Patch from solar to fix problems with get_name()

This commit is contained in:
Eric Andersen 2004-08-12 16:52:00 +00:00
parent 4014ab1c60
commit 9940e081c9

View File

@ -15,7 +15,7 @@
* that either displays or sets the characteristics of * that either displays or sets the characteristics of
* one or more of the system's networking interfaces. * one or more of the system's networking interfaces.
* *
* Version: $Id: interface.c,v 1.23 2004/07/23 01:49:46 bug1 Exp $ * Version: $Id: interface.c,v 1.24 2004/08/12 16:52:00 andersen Exp $
* *
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
* and others. Copyright 1993 MicroWalt Corporation * and others. Copyright 1993 MicroWalt Corporation
@ -986,31 +986,36 @@ static int if_readconf(void)
return err; return err;
} }
static char *get_name(char *name, char *p) char *get_name(char *name, char *p)
{ {
while (isspace(*p)) /* Extract <name>[:<alias>] from nul-terminated p where p matches
p++; <name>[:<alias>]: after leading whitespace.
while (*p) { If match is not made, set name empty and return unchanged p */
if (isspace(*p)) int namestart=0, nameend=0, aliasend;
break; while (isspace(p[namestart]))
if (*p == ':') { /* could be an alias */ namestart++;
char *dot = p, *dotname = name; nameend=namestart;
while (p[nameend] && p[nameend]!=':' && !isspace(p[nameend]))
*name++ = *p++; nameend++;
while (isdigit(*p)) if (p[nameend]==':') {
*name++ = *p++; aliasend=nameend+1;
if (*p != ':') { /* it wasn't, backup */ while (p[aliasend] && isdigit(p[aliasend]))
p = dot; aliasend++;
name = dotname; if (p[aliasend]==':') {
nameend=aliasend;
} }
if (*p == '\0') if ((nameend-namestart)<IFNAMSIZ) {
return NULL; memcpy(name,&p[namestart],nameend-namestart);
p++; name[nameend-namestart]='\0';
break; p=&p[nameend];
} else {
/* Interface name too large */
name[0]='\0';
} }
*name++ = *p++; } else {
/* first ':' not found - return empty */
name[0]='\0';
} }
*name++ = '\0';
return p; return p;
} }