diff mbox series

[4/5] Make terminating base64 sequences mandatory

Message ID 20200819230702.229822-5-mg@max.gautier.name
State New
Headers show
Series iconv: module for MODIFIED-UTF-7 | expand

Commit Message

Max Gautier Aug. 19, 2020, 11:07 p.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/modified-utf-7.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/iconvdata/modified-utf-7.c b/iconvdata/modified-utf-7.c
index e6eb784891..27cc4a88c3 100644
--- a/iconvdata/modified-utf-7.c
+++ b/iconvdata/modified-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;					      \
 	  }								      \