X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fbase64.c;h=cbe9a63cf123f869f64105d20aedb0579faa6405;hb=8ea6bf995cf561a525abc8f716e98c8a9b917496;hp=99fcc57c3cc220159cd4d5dc1ba54557e3c625b4;hpb=6829a6c0c428c91768aa4314752ba92b1340e11b;p=gnulib.git diff --git a/lib/base64.c b/lib/base64.c index 99fcc57c3..cbe9a63cf 100644 --- a/lib/base64.c +++ b/lib/base64.c @@ -19,7 +19,7 @@ * (mailbox/filter_trans.c, as of 2004-11-28). Improved by review * from Paul Eggert, Bruno Haible, and Stepan Kasal. * - * See also RFC 3548 . + * See also RFC 4648 . * * Be careful with error checking. Here is how you would typically * use these functions: @@ -552,10 +552,10 @@ base64_decode_alloc_ctx (struct base64_decode_context *ctx, { /* This may allocate a few bytes too many, depending on input, but it's not worth the extra CPU time to compute the exact size. - The exact size is 3 * inlen / 4, minus 1 if the input ends - with "=" and minus another 1 if the input ends with "==". + The exact size is 3 * (inlen + (ctx ? ctx->i : 0)) / 4, minus 1 if the + input ends with "=" and minus another 1 if the input ends with "==". Dividing before multiplying avoids the possibility of overflow. */ - size_t needlen = 3 * (inlen / 4) + 2; + size_t needlen = 3 * (inlen / 4) + 3; *out = malloc (needlen); if (!*out)