diff -ur jabberd-2.0s4.orig/c2s/authreg_pipe.c c2s/authreg_pipe.c --- jabberd-2.0s4.orig/c2s/authreg_pipe.c Fri Apr 30 02:46:41 2004 +++ c2s/authreg_pipe.c Mon Oct 25 18:54:46 2004 @@ -128,12 +128,12 @@ return 1; } - if(ap_base64decode_len(&buf[3]) >= 256) { + if(ap_base64decode_len(&buf[3], -1) >= 256) { log_debug(ZONE, "decoded password longer than buffer"); return 1; } - ap_base64decode(password, &buf[3]); + ap_base64decode(password, &buf[3], -1); log_debug(ZONE, "got password: %s", password); diff -ur jabberd-2.0s4.orig/sx/sasl.c sx/sasl.c --- jabberd-2.0s4.orig/sx/sasl.c Thu Apr 15 04:26:12 2004 +++ sx/sasl.c Mon Oct 25 18:56:32 2004 @@ -186,10 +186,9 @@ /** utility: decode incoming handshake data */ static void _sx_sasl_decode(char *in, int inlen, char **out, int *outlen) { - *outlen = ap_base64decode_len(in); - *out = (char *) malloc(sizeof(char) * *outlen); - ap_base64decode(*out, in); - (*outlen)--; + *outlen = ap_base64decode_len(in, inlen); + *out = (char *) malloc(sizeof(char) * (*outlen + 1)); + ap_base64decode(*out, in, inlen); } /** utility: encode outgoing handshake data */ diff -ur jabberd-2.0s4.orig/util/base64.c util/base64.c --- jabberd-2.0s4.orig/util/base64.c Thu Mar 27 01:57:17 2003 +++ util/base64.c Mon Oct 25 18:53:48 2004 @@ -86,32 +86,35 @@ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }; -int ap_base64decode_len(const char *bufcoded) +int ap_base64decode_len(const char *bufcoded, int buflen) { int nbytesdecoded; register const unsigned char *bufin; register int nprbytes; bufin = (const unsigned char *) bufcoded; - while (pr2six[*(bufin++)] <= 63); + while ((pr2six[*bufin] <= 63) && (buflen != 0)) { + bufin++; + buflen--; + } - nprbytes = (bufin - (const unsigned char *) bufcoded) - 1; - nbytesdecoded = ((nprbytes + 3) / 4) * 3; + nprbytes = bufin - (const unsigned char *) bufcoded; + nbytesdecoded = (nprbytes * 3) / 4; - return nbytesdecoded + 1; + return nbytesdecoded; } -int ap_base64decode(char *bufplain, const char *bufcoded) +int ap_base64decode(char *bufplain, const char *bufcoded, int buflen) { int len; - len = ap_base64decode_binary((unsigned char *) bufplain, bufcoded); + len = ap_base64decode_binary((unsigned char *) bufplain, bufcoded, buflen); bufplain[len] = '\0'; return len; } int ap_base64decode_binary(unsigned char *bufplain, - const char *bufcoded) + const char *bufcoded, int buflen) { int nbytesdecoded; register const unsigned char *bufin; @@ -119,8 +122,11 @@ register int nprbytes; bufin = (const unsigned char *) bufcoded; - while (pr2six[*(bufin++)] <= 63); - nprbytes = (bufin - (const unsigned char *) bufcoded) - 1; + while ((pr2six[*bufin] <= 63) && (buflen != 0)) { + bufin++; + buflen--; + } + nprbytes = bufin - (const unsigned char *) bufcoded; nbytesdecoded = ((nprbytes + 3) / 4) * 3; bufout = (unsigned char *) bufplain; @@ -221,10 +227,10 @@ int elen; char *out; - elen = ap_base64decode_len(buf); + elen = ap_base64decode_len(buf, -1); out = (char *) malloc(sizeof(char) * (elen + 1)); - ap_base64decode(out, buf); + ap_base64decode(out, buf, -1); return out; } diff -ur jabberd-2.0s4.orig/util/util.h util/util.h --- jabberd-2.0s4.orig/util/util.h Tue Oct 5 06:27:50 2004 +++ util/util.h Mon Oct 25 18:53:23 2004 @@ -657,9 +657,9 @@ /* base64 functions */ -extern int ap_base64decode_len(const char *bufcoded); -extern int ap_base64decode(char *bufplain, const char *bufcoded); -extern int ap_base64decode_binary(unsigned char *bufplain, const char *bufcoded); +extern int ap_base64decode_len(const char *bufcoded, int buflen); +extern int ap_base64decode(char *bufplain, const char *bufcoded, int buflen); +extern int ap_base64decode_binary(unsigned char *bufplain, const char *bufcoded, int buflen); extern int ap_base64encode_len(int len); extern int ap_base64encode(char *encoded, const char *string, int len); extern int ap_base64encode_binary(char *encoded, const unsigned char *string, int len);