e354a5
commit 9a99c682144bdbd40792ebf822fe9264e0376fb5
e354a5
Author: Arjun Shankar <arjun@redhat.com>
e354a5
Date:   Wed Nov 4 12:19:38 2020 +0100
e354a5
e354a5
    iconv: Accept redundant shift sequences in IBM1364 [BZ #26224]
e354a5
    
e354a5
    The IBM1364, IBM1371, IBM1388, IBM1390 and IBM1399 character sets
e354a5
    share converter logic (iconvdata/ibm1364.c) which would reject
e354a5
    redundant shift sequences when processing input in these character
e354a5
    sets.  This led to a hang in the iconv program (CVE-2020-27618).
e354a5
    
e354a5
    This commit adjusts the converter to ignore redundant shift sequences
e354a5
    and adds test cases for iconv_prog hangs that would be triggered upon
e354a5
    their rejection.  This brings the implementation in line with other
e354a5
    converters that also ignore redundant shift sequences (e.g. IBM930
e354a5
    etc., fixed in commit 692de4b3960d).
e354a5
    
e354a5
    Reviewed-by: Carlos O'Donell <carlos@redhat.com>
e354a5
e354a5
diff --git a/iconv/tst-iconv_prog.sh b/iconv/tst-iconv_prog.sh
e354a5
index 8298136b7f45d855..d8db7b335c1fcca2 100644
e354a5
--- a/iconv/tst-iconv_prog.sh
e354a5
+++ b/iconv/tst-iconv_prog.sh
e354a5
@@ -102,12 +102,16 @@ hangarray=(
e354a5
 "\x00\x80;-c;IBM1161;UTF-8//TRANSLIT//IGNORE"
e354a5
 "\x00\xdb;-c;IBM1162;UTF-8//TRANSLIT//IGNORE"
e354a5
 "\x00\x70;-c;IBM12712;UTF-8//TRANSLIT//IGNORE"
e354a5
-# These are known hangs that are yet to be fixed:
e354a5
-# "\x00\x0f;-c;IBM1364;UTF-8"
e354a5
-# "\x00\x0f;-c;IBM1371;UTF-8"
e354a5
-# "\x00\x0f;-c;IBM1388;UTF-8"
e354a5
-# "\x00\x0f;-c;IBM1390;UTF-8"
e354a5
-# "\x00\x0f;-c;IBM1399;UTF-8"
e354a5
+"\x00\x0f;-c;IBM1364;UTF-8"
e354a5
+"\x0e\x0e;-c;IBM1364;UTF-8"
e354a5
+"\x00\x0f;-c;IBM1371;UTF-8"
e354a5
+"\x0e\x0e;-c;IBM1371;UTF-8"
e354a5
+"\x00\x0f;-c;IBM1388;UTF-8"
e354a5
+"\x0e\x0e;-c;IBM1388;UTF-8"
e354a5
+"\x00\x0f;-c;IBM1390;UTF-8"
e354a5
+"\x0e\x0e;-c;IBM1390;UTF-8"
e354a5
+"\x00\x0f;-c;IBM1399;UTF-8"
e354a5
+"\x0e\x0e;-c;IBM1399;UTF-8"
e354a5
 "\x00\x53;-c;IBM16804;UTF-8//TRANSLIT//IGNORE"
e354a5
 "\x00\x41;-c;IBM274;UTF-8//TRANSLIT//IGNORE"
e354a5
 "\x00\x41;-c;IBM275;UTF-8//TRANSLIT//IGNORE"
e354a5
diff --git a/iconvdata/ibm1364.c b/iconvdata/ibm1364.c
e354a5
index 517fe60813be0472..ecc3f8ddddbdbc8c 100644
e354a5
--- a/iconvdata/ibm1364.c
e354a5
+++ b/iconvdata/ibm1364.c
e354a5
@@ -158,24 +158,14 @@ enum
e354a5
 									      \
e354a5
     if (__builtin_expect (ch, 0) == SO)					      \
e354a5
       {									      \
e354a5
-	/* Shift OUT, change to DBCS converter.  */			      \
e354a5
-	if (curcs == db)						      \
e354a5
-	  {								      \
e354a5
-	    result = __GCONV_ILLEGAL_INPUT;				      \
e354a5
-	    break;							      \
e354a5
-	  }								      \
e354a5
+	/* Shift OUT, change to DBCS converter (redundant escape okay).  */   \
e354a5
 	curcs = db;							      \
e354a5
 	++inptr;							      \
e354a5
 	continue;							      \
e354a5
       }									      \
e354a5
     if (__builtin_expect (ch, 0) == SI)					      \
e354a5
       {									      \
e354a5
-	/* Shift IN, change to SBCS converter.  */			      \
e354a5
-	if (curcs == sb)						      \
e354a5
-	  {								      \
e354a5
-	    result = __GCONV_ILLEGAL_INPUT;				      \
e354a5
-	    break;							      \
e354a5
-	  }								      \
e354a5
+	/* Shift IN, change to SBCS converter (redundant escape okay).  */    \
e354a5
 	curcs = sb;							      \
e354a5
 	++inptr;							      \
e354a5
 	continue;							      \