From b962fb6be048bc753a4131b6f690c25c5d45b3c5 Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Mon, 4 Oct 2021 13:47:51 +0200 Subject: rfc2047: skip whitespace everywhere during base64 decoding > The encoded output stream must be represented in lines of no more > than 76 characters each. All line breaks or other characters not > found in Table 1 must be ignored by decoding software. In base64 > data, characters other than those in Table 1, line breaks, and other > white space probably indicate a transmission error, about which a > warning message or even a message rejection might be appropriate > under some circumstances. --- rfc2047.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'rfc2047.c') diff --git a/rfc2047.c b/rfc2047.c index b581976..3074b4d 100644 --- a/rfc2047.c +++ b/rfc2047.c @@ -82,16 +82,25 @@ blaze822_decode_b64(char *s, char *e, char **deco, size_t *decleno) *deco = buf; while (s + 4 <= e) { - while (s < e && isfws((unsigned char)*s)) - s++; - if (s >= e) - break; - uint32_t v = 0; unsigned char t = 0; - unsigned char c0 = s[0], c1 = s[1], c2 = s[2], c3 = s[3]; - s += 4; +#define SKIP_WS \ + while (s < e && isfws((unsigned char)*s)) \ + s++; \ + if (s >= e) \ + break; + + SKIP_WS; + unsigned char c0 = *s++; + SKIP_WS; + unsigned char c1 = *s++; + SKIP_WS; + unsigned char c2 = *s++; + SKIP_WS; + unsigned char c3 = *s++; + +#undef SKIP_WS if ((c0 | c1 | c2 | c3) > 127) goto error; -- cgit 1.4.1