Changeset 852 for branches


Ignore:
Timestamp:
06/21/10 17:41:30 (20 months ago)
Author:
elly
Message:

Fix hostcrypt memory corruption bug.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ithildin-1.1/modules/ircd/addons/hostcrypt.c

    r823 r852  
    220220 
    221221    if (from->client != NULL) 
    222         sm.len = sprintf(buf, ":%s!%s@%s %s %s%s", from->client->nick, 
     222        sm.len = snprintf(buf, sizeof(buf), ":%s!%s@%s %s %s%s", from->client->nick, 
    223223                from->client->user, from->client->orighost, cmd, 
    224224                (to != NULL ? to : ""), (to != NULL ? " " : "")); 
    225225    else if (from->server != NULL) 
    226         sm.len = sprintf(buf, ":%s %s %s%s", from->server->name, cmd,  
     226        sm.len = snprintf(buf, sizeof(buf), ":%s %s %s%s", from->server->name, cmd,  
    227227                (to != NULL ? to : ""), (to != NULL ? " " : "")); 
    228228    else 
    229         sm.len = sprintf(buf, "%s %s%s", cmd, 
     229        sm.len = snprintf(buf, sizeof(buf), "%s %s%s", cmd, 
    230230                (to != NULL ? to : ""), (to != NULL ? " " : "")); 
    231231    if (msg != NULL) 
     
    326326        /* this is the easy case.. */ 
    327327        if ((s = strchr(cli->orighost, '.')) != NULL) 
    328             sprintf(buf, "%s%u%s%s", hostcrypt.prefix, hash, s, 
     328            snprintf(buf, sizeof(buf), "%s%u%s%s", hostcrypt.prefix, hash, s, 
    329329                    hostcrypt.suffix); 
    330330        else 
    331             sprintf(buf, "%s%u.%s%s", hostcrypt.prefix, hash, cli->orighost, 
     331            snprintf(buf, sizeof(buf), "%s%u.%s%s", hostcrypt.prefix, hash, cli->orighost, 
    332332                    hostcrypt.suffix); 
    333333 
     
    345345        memset(s + 8, 0, 8); /* blech. ;) */ 
    346346        inet_ntop(PF_INET6, &i6a, buf, HOSTLEN + 1); 
    347         sprintf(buf + strlen(buf), "%u", hash); 
     347        snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%u", hash); 
    348348 
    349349        return buf; 
     
    360360    phash = (austhex_hash(quads[0]) + austhex_hash(quads[1]) + 
    361361            austhex_hash(quads[2])) % AUSTHEX_HASH_SMALL; 
    362     sprintf(buf, "%s.%s.%u.%u", quads[0], quads[1], phash, hash); 
     362    snprintf(buf, sizeof(buf), "%s.%s.%u.%u", quads[0], quads[1], phash, hash); 
    363363 
    364364    return buf; 
     
    422422        if (s == NULL) 
    423423            /* singleton string like 'localhost' */ 
    424             sprintf(buf, "%32s.%s", md5buf, cli->orighost); 
     424            snprintf(buf, sizeof(buf), "%32s.%s", md5buf, cli->orighost); 
    425425        else { 
    426426            while (*s != '.' && s > cli->orighost) 
     
    428428            if (s == cli->orighost) 
    429429                /* host is in pure domain.tld form */ 
    430                 sprintf(buf, "%32s.%s", md5buf, cli->orighost); 
     430                snprintf(buf, sizeof(buf), "%32s.%s", md5buf, cli->orighost); 
    431431            else 
    432432                /* s is the second to last . in the string now */ 
    433                 sprintf(buf, "%s", s + 1); 
     433                snprintf(buf, sizeof(buf), "%s", s + 1); 
    434434        } 
    435435        /* buf now contains the host we wish to md5 on */ 
Note: See TracChangeset for help on using the changeset viewer.