You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Peter 'Luna' Altberg <pe...@altberg.nu> on 1999/03/11 21:01:14 UTC

Bug in ap_uuencode

The function ap_uuencode in util.c has a (maybe compiler dependent)
buffer overflow. Look:

API_EXPORT(char *) ap_uuencode(pool *a, char *string) 
{ 
    int i, len = strlen(string); 
    char *p; 
    char *encoded = (char *) ap_pcalloc(a, (len+2) / 3 * 4);

The calculation of the needed size of 'encoded' is one byte short (no
room for terminating '\0') if the '(len+2)/3' is converted to integer
before '* 4' (as it seems to be on Visual C++ 6.0).

Cheers,
Peter

Re: Bug in ap_uuencode

Posted by Dean Gaudet <dg...@arctic.org>.
On Thu, 11 Mar 1999, Peter 'Luna' Altberg wrote:

> The function ap_uuencode in util.c has a (maybe compiler dependent)
> buffer overflow. Look:
> 
> API_EXPORT(char *) ap_uuencode(pool *a, char *string) 
> { 
>     int i, len = strlen(string); 
>     char *p; 
>     char *encoded = (char *) ap_pcalloc(a, (len+2) / 3 * 4);
> 
> The calculation of the needed size of 'encoded' is one byte short (no
> room for terminating '\0') if the '(len+2)/3' is converted to integer
> before '* 4' (as it seems to be on Visual C++ 6.0).

That's not the only bug...

It declares "char *string" -- which is signed in many implementations, and
then does things such as:

        *p++ = basis_64[string[i] >> 2];

string[i] >> 2 is sign extended for 8-bit characters -- definately doing
the wrong thing.

It uses string[i + 2] even in cases where i + 2 > strlen(string).

And the *p-- stuff at the end appears to assume that strlen(string) % 3 ==
1. 

ap_uuencode doesn't appear to be used anywhere in apache currently. 

Dean