$OpenBSD: patch-source_misc_c,v 1.2 2004/01/04 23:46:49 espie Exp $ --- source/misc.c.orig 2001-01-08 07:24:22.000000000 +0100 +++ source/misc.c 2004-01-05 00:37:21.000000000 +0100 @@ -3108,42 +3108,47 @@ char *cluster (char *hostname) static char result[IRCD_BUFFER_SIZE/4 + 1]; char temphost[BIG_BUFFER_SIZE + 1]; char *host; + char *atsign; if (!hostname) return NULL; - host = temphost; - *result = 0; - memset(result, 0, sizeof(result)); - memset(temphost, 0, sizeof(temphost)); - if (strchr(hostname, '@')) - { - if (*hostname == '~') - hostname++; - strcpy(result, hostname); - *strchr(result, '@') = '\0'; - if (strlen(result) > 9) - { - result[8] = '*'; - result[9] = '\0'; - } - strcat(result, "@"); - if (!(hostname = strchr(hostname, '@'))) - return NULL; - hostname++; + + atsign = strchr(hostname, '@'); + if (atsign) { + if (*hostname == '~') { + strcpy(result, "~*@"); + } else { + size_t ident_len = atsign - hostname; + + if (ident_len <= 9) { + /* copy ident@ */ + strmcpy(result, hostname, ident_len + 1); + } else { + strmcpy(result, hostname, 8); + result[8] = '*'; + result[9] = '@'; + result[10] = '\0'; + } + } + hostname = atsign + 1; + } else { + *result = 0; } - strcpy(host, hostname); - if (*host && isdigit(*(host + strlen(host) - 1))) + strlcpy(temphost, hostname, sizeof temphost); + host = temphost; + + if (*host && isdigit((unsigned char)*(host + strlen(host) - 1))) { /* Thanks icebreak for this small patch which fixes this function */ int i; char *tmp; - char count=0; + char count = 0; tmp = host; - while((tmp-host)