www-apache-bugdb mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Philipp Knirsch" <p...@kyb.tuebingen.mpg.de>
Subject Re: protocol/3422: main/util.c: ap_uuencode and ap_uudecode memory leaks and wrong output
Date Sun, 22 Nov 1998 12:31:55 GMT
Hi.

A small glich has occured to my onw patch as well, i checked in the for
loops of the ap_uudecode() for '=' instead of for the 64.

Here is the changed ap_uudecode:

------------------------ cut here -------------------------------------------


API_EXPORT(char *) ap_uudecode(pool *p, const char *bufcoded)
{           
    int nbytesdecoded, i;
    unsigned char temp[4];
    register const unsigned char *bufin;
    register char *bufplain;
    register unsigned char *bufout;
    register int nprbytes;

    /* Strip leading whitespace. */
        
    while (*bufcoded == ' ' || *bufcoded == '\t')
        bufcoded++;
    
    /* Figure out how many characters are in the input buffer.
     * Allocate this many from the per-transaction pool for the result.
     */
#ifndef CHARSET_EBCDIC
    bufin = (const unsigned char *) bufcoded;
    while (pr2six[*(bufin++)] <= 63);
    nprbytes = (bufin - (const unsigned char *) bufcoded) - 1;
    nbytesdecoded = ((nprbytes + 3) / 4) * 3;
    
    bufplain = ap_palloc(p, nbytesdecoded + 1);
    bufout = (unsigned char *) bufplain;
    
    bufin = (const unsigned char *) bufcoded;
    
    while (nprbytes > 0) { 
        for(i=0; i<4 && pr2six[bufin[i]] != 64; i++)
            temp[i] = pr2six[bufin[i]];

        while(i<4)
            temp[i++] = 0;  

        *(bufout++) =
            (unsigned char) (temp[0] << 2 | temp[1] >> 4);
        *(bufout++) =
            (unsigned char) (temp[1] << 4 | temp[2] >> 2);
        *(bufout++) =
            (unsigned char) (temp[2] << 6 | temp[3]);
    
        bufin += 4;
        nprbytes -= 4;
    }
    
    bufplain[nbytesdecoded] = '\0';
#else /*CHARSET_EBCDIC*/
    bufin = (const unsigned char *) bufcoded;
    while (pr2six[os_toascii[(unsigned char)*(bufin++)]] <= 63);
    nprbytes = (bufin - (const unsigned char *) bufcoded) - 1;
    nbytesdecoded = ((nprbytes + 3) / 4) * 3;
    
    bufplain = ap_palloc(p, nbytesdecoded + 1);
    bufout = (unsigned char *) bufplain;
    
    bufin = (const unsigned char *) bufcoded;
 
    while (nprbytes > 0) {            
        for(i=0; i<4 && os_toascii[(unsigned char)pr2six[bufin[i]]] != 64; i++)
            temp[i] = os_toascii[(unsigned char)pr2six[bufin[i]]];      

        while(i<4)
            temp[i++] = 0;

        *(bufout++) = os_toebcdic[    
            (unsigned char) (temp[0] << 2 | temp[1] >> 4)];
        *(bufout++) = os_toebcdic[    
            (unsigned char) (temp[1] << 4 | temp[2] >> 2)];
        *(bufout++) = os_toebcdic[    
            (unsigned char) (temp[2] << 6 | temp[3])];

        bufin += 4;
        nprbytes -= 4;
    }

    bufplain[nbytesdecoded] = '\0';   
#endif /*CHARSET_EBCDIC*/
    return bufplain;
}

------------------------------------- cut here ------------------------------


-- 
            _________          _______        _____      ___    _
\__________/         \________/       \______/     \____/   \__/ \/\|
                             Philipp Knirsch
        Unix, Internet and Java consulting, programming and design.

                       phone: +49 7121 907033
                       email: phil@linux.de
                       www:   http://www.wizards.de/phil

Motd: The pen is only mighter than the sword at a range greater than five feet.

Mime
View raw message