[v3,4/5] Make terminating base64 sequences mandatory
Commit Message
In the modified UTF-7 encoding, unlike in UTF-7, one MUST terminate all
base64 sequence with the '-' character.
MODIFIED-UTF-7 -> INTERNAL : make unterminated sequences illegal
INTERNAL -> MODIFIED-UTF-7 : always terminate the sequences
---
iconvdata/imap-utf-7.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
Comments
* Max Gautier via Libc-alpha:
> In the modified UTF-7 encoding, unlike in UTF-7, one MUST terminate all
> base64 sequence with the '-' character.
> MODIFIED-UTF-7 -> INTERNAL : make unterminated sequences illegal
> INTERNAL -> MODIFIED-UTF-7 : always terminate the sequences
Still mentions MODIFIED-UTF-7. This should be folded into the main
patch (conditional for UTF-7-IMAP). The explanation in the commit
message should be put into a source code comment.
Thanks,
Florian
@@ -176,7 +176,7 @@ base64 (unsigned int i)
i = 62; \
else if (ch == ',') \
i = 63; \
- else \
+ else if (ch == '-') \
{ \
/* Terminate base64 encoding. */ \
\
@@ -188,12 +188,14 @@ base64 (unsigned int i)
STANDARD_FROM_LOOP_ERR_HANDLER ((statep->__count = 0, 1)); \
} \
\
- if (ch == '-') \
- inptr++; \
+ inptr++; \
\
statep->__count = 0; \
continue; \
} \
+ else \
+ STANDARD_FROM_LOOP_ERR_HANDLER ((statep->__count = 0, 1)); \
+ /* Terminating '-' is required */ \
\
/* Concatenate the base64 integer i to the accumulator. */ \
shift = (statep->__count >> 3); \
@@ -354,8 +356,7 @@ base64 (unsigned int i)
\
if ((statep->__count & 0x18) >= 0x10) \
*outptr++ = base64 ((statep->__count >> 3) & ~3); \
- if (ismbase64 (ch)) \
- *outptr++ = '-'; \
+ *outptr++ = '-'; \
*outptr++ = (unsigned char) ch; \
statep->__count = 0; \
} \