X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fsrc%2Fbase64.c;h=cee77c3c3334c6715a9f02fecb5bc53f36203183;hb=01f3091ab20e5b78419d2b7cff106b421600e553;hp=f4c4f233b0105fd03547b44edd1cab07cae391a6;hpb=f4d091fbe1f4cc0a6a7c11c174eaca32402290ec;p=user%2Fhenk%2Fcode%2Fexim.git diff --git a/src/src/base64.c b/src/src/base64.c index f4c4f233b..cee77c3c3 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 - 2015 */ +/* Copyright (c) University of Cambridge 1995 - 2016 */ /* See the file NOTICE for conditions of use and distribution. */ @@ -100,21 +100,21 @@ return size; #endif /*WITH_CONTENT_SCAN*/ /************************************************* -/************************************************* -/************************************************* -/************************************************* -/************************************************* -/************************************************* -/************************************************* -/************************************************* -/************************************************* -/************************************************* -/************************************************* -/************************************************* -/************************************************* -/************************************************* -/************************************************* -/************************************************* + ************************************************* + ************************************************* + ************************************************* + ************************************************* + ************************************************* + ************************************************* + ************************************************* + ************************************************* + ************************************************* + ************************************************* + ************************************************* + ************************************************* + ************************************************* + ************************************************* + *************************************************/ /************************************************* @@ -129,11 +129,12 @@ compact loop is messy and would probably run more slowly. Arguments: code points to the coded string, zero-terminated ptr where to put the pointer to the result, which is in - dynamic store, and zero-terminated + allocated store, and zero-terminated Returns: the number of bytes in the result, or -1 if the input was malformed +Whitespace in the input is ignored. A zero is added on to the end to make it easy in cases where the result is to be interpreted as text. This is not included in the count. */ @@ -161,28 +162,51 @@ quantum this may decode to 1, 2, or 3 output bytes. */ while ((x = *code++) != 0) { + if (isspace(x)) continue; + /* debug_printf("b64d: '%c'\n", x); */ + if (x > 127 || (x = dec64table[x]) == 255) return -1; - if ((y = *code++) == 0 || (y = dec64table[y]) == 255) + + while (isspace(y = *code++)) ; + /* debug_printf("b64d: '%c'\n", y); */ + if (y == 0 || (y = dec64table[y]) == 255) return -1; *result++ = (x << 2) | (y >> 4); + /* debug_printf("b64d: -> %02x\n", result[-1]); */ - if ((x = *code++) == '=') + while (isspace(x = *code++)) ; + /* debug_printf("b64d: '%c'\n", x); */ + if (x == '=') /* endmarker, but there should be another */ { - if (*code++ != '=' || *code != 0) return -1; + while (isspace(x = *code++)) ; + /* debug_printf("b64d: '%c'\n", x); */ + if (x != '=') return -1; + while (isspace(y = *code++)) ; + if (y != 0) return -1; + /* debug_printf("b64d: DONE\n"); */ + break; } else { if (x > 127 || (x = dec64table[x]) == 255) return -1; *result++ = (y << 4) | (x >> 2); - if ((y = (*code++)) == '=') + /* debug_printf("b64d: -> %02x\n", result[-1]); */ + + while (isspace(y = *code++)) ; + /* debug_printf("b64d: '%c'\n", y); */ + if (y == '=') { - if (*code != 0) return -1; + while (isspace(y = *code++)) ; + if (y != 0) return -1; + /* debug_printf("b64d: DONE\n"); */ + break; } else { if (y > 127 || (y = dec64table[y]) == 255) return -1; *result++ = (x << 6) | y; + /* debug_printf("b64d: -> %02x\n", result[-1]); */ } } } @@ -192,23 +216,6 @@ return result - *ptr; } -/************************************************* -/************************************************* -/************************************************* -/************************************************* -/************************************************* -/************************************************* -/************************************************* -/************************************************* -/************************************************* -/************************************************* -/************************************************* -/************************************************* -/************************************************* -/************************************************* -/************************************************* -/************************************************* - /************************************************* * Encode byte-string in base 64 * *************************************************/