[v3,4/5] Make terminating base64 sequences mandatory

Message ID 20210125090226.39967-5-mg@max.gautier.name
State Changes Requested, archived
Headers
Series iconv: module for IMAP-UTF-7 |

Commit Message

Max Gautier Jan. 25, 2021, 9:02 a.m. UTC
  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

Florian Weimer Feb. 7, 2021, 9:45 a.m. UTC | #1
* 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
  

Patch

diff --git a/iconvdata/imap-utf-7.c b/iconvdata/imap-utf-7.c
index ebd66d3388..45629a48f8 100644
--- a/iconvdata/imap-utf-7.c
+++ b/iconvdata/imap-utf-7.c
@@ -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;					      \
 	  }								      \