X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=src%2Fsrc%2Fbase64.c;h=6c8191462a9c8cd63c9c88c744b8590c6b638315;hb=53738d6ab53ad3b53e5e8db08de4849168e5cc14;hp=f6f187f075a0f924b6915872af9900e09ba0d580;hpb=c5db348c5e29e93e51389fa0079f829967c5da82;p=exim.git diff --git a/src/src/base64.c b/src/src/base64.c index f6f187f07..6c8191462 100644 --- a/src/src/base64.c +++ b/src/src/base64.c @@ -5,7 +5,7 @@ /* Copyright (c) Tom Kistner 2004, 2015 */ /* License: GPL */ -/* Copyright (c) University of Cambridge 1995 - 2017 */ +/* Copyright (c) University of Cambridge 1995 - 2018 */ /* See the file NOTICE for conditions of use and distribution. */ @@ -38,7 +38,7 @@ ssize_t mime_decode_base64(FILE * in, FILE * out, uschar * boundary) { uschar ibuf[MIME_MAX_LINE_LENGTH], obuf[MIME_MAX_LINE_LENGTH]; -uschar *ipos, *opos; +uschar *opos; ssize_t len, size = 0; int bytestate = 0; @@ -52,7 +52,7 @@ while (Ufgets(ibuf, MIME_MAX_LINE_LENGTH, in) != NULL) ) break; - for (ipos = ibuf ; *ipos != '\r' && *ipos != '\n' && *ipos != 0; ++ipos) + for (uschar * ipos = ibuf ; *ipos != '\r' && *ipos != '\n' && *ipos; ++ipos) if (*ipos == '=') /* skip padding */ ++bytestate; @@ -152,10 +152,14 @@ static uschar dec64table[] = { int b64decode(const uschar *code, uschar **ptr) { + int x, y; -uschar *result = store_get(3*(Ustrlen(code)/4) + 1); +uschar *result; -*ptr = result; +{ + int l = Ustrlen(code); + *ptr = result = store_get(1 + l/4 * 3 + l%4, is_tainted(code)); +} /* Each cycle of the loop handles a quantum of 4 input bytes. For the last quantum this may decode to 1, 2, or 3 output bytes. */ @@ -169,7 +173,7 @@ while ((x = *code++) != 0) while (isspace(y = *code++)) ; /* debug_printf("b64d: '%c'\n", y); */ - if (y == 0 || (y = dec64table[y]) == 255) + if (y > 127 || (y = dec64table[y]) == 255) return -1; *result++ = (x << 2) | (y >> 4); @@ -238,14 +242,14 @@ static uschar *enc64table = US"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; uschar * -b64encode(uschar *clear, int len) +b64encode(const uschar * clear, int len) { -uschar *code = store_get(4*((len+2)/3) + 1); +uschar *code = store_get(4*((len+2)/3) + 1, is_tainted(clear)); uschar *p = code; while (len-- >0) { - register int x, y; + int x, y; x = *clear++; *p++ = enc64table[(x >> 2) & 63];