Changeset View
Changeset View
Standalone View
Standalone View
contrib/telnet/telnetd/utility.c
Show All 12 Lines | |||||
char editedhost[32]; | char editedhost[32]; | ||||
void | void | ||||
edithost(char *pat, char *host) | edithost(char *pat, char *host) | ||||
{ | { | ||||
char *res = editedhost; | char *res = editedhost; | ||||
if (!pat) | if (pat) { | ||||
pat = strdup(""); | while (*pat) { | ||||
markm: Oooh, yuk. Well spotted. | |||||
while (*pat) { | switch (*pat) { | ||||
switch (*pat) { | |||||
case '#': | |||||
if (*host) | |||||
host++; | |||||
break; | |||||
case '@': | case '#': | ||||
if (*host) | if (*host) | ||||
*res++ = *host++; | host++; | ||||
break; | break; | ||||
default: | case '@': | ||||
*res++ = *pat; | if (*host) | ||||
break; | *res++ = *host++; | ||||
} | break; | ||||
if (res == &editedhost[sizeof editedhost - 1]) { | |||||
*res = '\0'; | default: | ||||
return; | *res++ = *pat; | ||||
break; | |||||
} | |||||
if (res == &editedhost[sizeof editedhost - 1]) { | |||||
*res = '\0'; | |||||
return; | |||||
} | |||||
pat++; | |||||
} | } | ||||
pat++; | |||||
} | } | ||||
if (*host) | if (*host) | ||||
(void) strncpy(res, host, | (void) strncpy(res, host, | ||||
sizeof editedhost - (res - editedhost) -1); | sizeof editedhost - (res - editedhost) -1); | ||||
else | else | ||||
*res = '\0'; | *res = '\0'; | ||||
editedhost[sizeof editedhost - 1] = '\0'; | editedhost[sizeof editedhost - 1] = '\0'; | ||||
} | } | ||||
Show All 12 Lines |
Oooh, yuk. Well spotted.