|
|
e354a5 |
commit ee7a3144c9922808181009b7b3e50e852fb4999b
|
|
|
e354a5 |
Author: Andreas Schwab <schwab@suse.de>
|
|
|
e354a5 |
Date: Mon Dec 21 08:56:43 2020 +0530
|
|
|
e354a5 |
|
|
|
e354a5 |
Fix buffer overrun in EUC-KR conversion module (bz #24973)
|
|
|
e354a5 |
|
|
|
e354a5 |
The byte 0xfe as input to the EUC-KR conversion denotes a user-defined
|
|
|
e354a5 |
area and is not allowed. The from_euc_kr function used to skip two bytes
|
|
|
e354a5 |
when told to skip over the unknown designation, potentially running over
|
|
|
e354a5 |
the buffer end.
|
|
|
e354a5 |
|
|
|
e354a5 |
# Conflicts:
|
|
|
e354a5 |
# iconvdata/Makefile
|
|
|
e354a5 |
|
|
|
e354a5 |
diff --git a/iconvdata/Makefile b/iconvdata/Makefile
|
|
|
e354a5 |
index 06e161d9b8f67118..a47a4c07cd2e3d1b 100644
|
|
|
e354a5 |
--- a/iconvdata/Makefile
|
|
|
e354a5 |
+++ b/iconvdata/Makefile
|
|
|
e354a5 |
@@ -73,7 +73,7 @@ modules.so := $(addsuffix .so, $(modules))
|
|
|
e354a5 |
ifeq (yes,$(build-shared))
|
|
|
e354a5 |
tests = bug-iconv1 bug-iconv2 tst-loading tst-e2big tst-iconv4 bug-iconv4 \
|
|
|
e354a5 |
tst-iconv6 bug-iconv5 bug-iconv6 tst-iconv7 bug-iconv8 bug-iconv9 \
|
|
|
e354a5 |
- bug-iconv10 bug-iconv11 bug-iconv12
|
|
|
e354a5 |
+ bug-iconv10 bug-iconv11 bug-iconv12 bug-iconv13
|
|
|
e354a5 |
ifeq ($(have-thread-library),yes)
|
|
|
e354a5 |
tests += bug-iconv3
|
|
|
e354a5 |
endif
|
|
|
e354a5 |
diff --git a/iconvdata/bug-iconv13.c b/iconvdata/bug-iconv13.c
|
|
|
e354a5 |
new file mode 100644
|
|
|
e354a5 |
index 0000000000000000..87aaff398e0f6167
|
|
|
e354a5 |
--- /dev/null
|
|
|
e354a5 |
+++ b/iconvdata/bug-iconv13.c
|
|
|
e354a5 |
@@ -0,0 +1,53 @@
|
|
|
e354a5 |
+/* bug 24973: Test EUC-KR module
|
|
|
e354a5 |
+ Copyright (C) 2020 Free Software Foundation, Inc.
|
|
|
e354a5 |
+ This file is part of the GNU C Library.
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
e354a5 |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
e354a5 |
+ License as published by the Free Software Foundation; either
|
|
|
e354a5 |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
e354a5 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
e354a5 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
e354a5 |
+ Lesser General Public License for more details.
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
e354a5 |
+ License along with the GNU C Library; if not, see
|
|
|
e354a5 |
+ <https://www.gnu.org/licenses/>. */
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+#include <errno.h>
|
|
|
e354a5 |
+#include <iconv.h>
|
|
|
e354a5 |
+#include <stdio.h>
|
|
|
e354a5 |
+#include <support/check.h>
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+static int
|
|
|
e354a5 |
+do_test (void)
|
|
|
e354a5 |
+{
|
|
|
e354a5 |
+ iconv_t cd = iconv_open ("UTF-8//IGNORE", "EUC-KR");
|
|
|
e354a5 |
+ TEST_VERIFY_EXIT (cd != (iconv_t) -1);
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ /* 0xfe (->0x7e : row 94) and 0xc9 (->0x49 : row 41) are user-defined
|
|
|
e354a5 |
+ areas, which are not allowed and should be skipped over due to
|
|
|
e354a5 |
+ //IGNORE. The trailing 0xfe also is an incomplete sequence, which
|
|
|
e354a5 |
+ should be checked first. */
|
|
|
e354a5 |
+ char input[4] = { '\xc9', '\xa1', '\0', '\xfe' };
|
|
|
e354a5 |
+ char *inptr = input;
|
|
|
e354a5 |
+ size_t insize = sizeof (input);
|
|
|
e354a5 |
+ char output[4];
|
|
|
e354a5 |
+ char *outptr = output;
|
|
|
e354a5 |
+ size_t outsize = sizeof (output);
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ /* This used to crash due to buffer overrun. */
|
|
|
e354a5 |
+ TEST_VERIFY (iconv (cd, &inptr, &insize, &outptr, &outsize) == (size_t) -1);
|
|
|
e354a5 |
+ TEST_VERIFY (errno == EINVAL);
|
|
|
e354a5 |
+ /* The conversion should produce one character, the converted null
|
|
|
e354a5 |
+ character. */
|
|
|
e354a5 |
+ TEST_VERIFY (sizeof (output) - outsize == 1);
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ TEST_VERIFY_EXIT (iconv_close (cd) != -1);
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ return 0;
|
|
|
e354a5 |
+}
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+#include <support/test-driver.c>
|
|
|
e354a5 |
diff --git a/iconvdata/euc-kr.c b/iconvdata/euc-kr.c
|
|
|
e354a5 |
index 73e02817a07e873d..dc7eaa6596f5d4d4 100644
|
|
|
e354a5 |
--- a/iconvdata/euc-kr.c
|
|
|
e354a5 |
+++ b/iconvdata/euc-kr.c
|
|
|
e354a5 |
@@ -80,11 +80,7 @@ euckr_from_ucs4 (uint32_t ch, unsigned char *cp)
|
|
|
e354a5 |
\
|
|
|
e354a5 |
if (ch <= 0x9f) \
|
|
|
e354a5 |
++inptr; \
|
|
|
e354a5 |
- /* 0xfe(->0x7e : row 94) and 0xc9(->0x59 : row 41) are \
|
|
|
e354a5 |
- user-defined areas. */ \
|
|
|
e354a5 |
- else if (__builtin_expect (ch == 0xa0, 0) \
|
|
|
e354a5 |
- || __builtin_expect (ch > 0xfe, 0) \
|
|
|
e354a5 |
- || __builtin_expect (ch == 0xc9, 0)) \
|
|
|
e354a5 |
+ else if (__glibc_unlikely (ch == 0xa0)) \
|
|
|
e354a5 |
{ \
|
|
|
e354a5 |
/* This is illegal. */ \
|
|
|
e354a5 |
STANDARD_FROM_LOOP_ERR_HANDLER (1); \
|
|
|
e354a5 |
diff --git a/iconvdata/ksc5601.h b/iconvdata/ksc5601.h
|
|
|
e354a5 |
index 5588d3a14b667b42..fa2d30677c41f46a 100644
|
|
|
e354a5 |
--- a/iconvdata/ksc5601.h
|
|
|
e354a5 |
+++ b/iconvdata/ksc5601.h
|
|
|
e354a5 |
@@ -50,15 +50,15 @@ ksc5601_to_ucs4 (const unsigned char **s, size_t avail, unsigned char offset)
|
|
|
e354a5 |
unsigned char ch2;
|
|
|
e354a5 |
int idx;
|
|
|
e354a5 |
|
|
|
e354a5 |
+ if (avail < 2)
|
|
|
e354a5 |
+ return 0;
|
|
|
e354a5 |
+
|
|
|
e354a5 |
/* row 94(0x7e) and row 41(0x49) are user-defined area in KS C 5601 */
|
|
|
e354a5 |
|
|
|
e354a5 |
if (ch < offset || (ch - offset) <= 0x20 || (ch - offset) >= 0x7e
|
|
|
e354a5 |
|| (ch - offset) == 0x49)
|
|
|
e354a5 |
return __UNKNOWN_10646_CHAR;
|
|
|
e354a5 |
|
|
|
e354a5 |
- if (avail < 2)
|
|
|
e354a5 |
- return 0;
|
|
|
e354a5 |
-
|
|
|
e354a5 |
ch2 = (*s)[1];
|
|
|
e354a5 |
if (ch2 < offset || (ch2 - offset) <= 0x20 || (ch2 - offset) >= 0x7f)
|
|
|
e354a5 |
return __UNKNOWN_10646_CHAR;
|