1 /* bug 24973: Test EUC-KR module
2 Copyright (C) 2020-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19 #include <errno.h>
20 #include <iconv.h>
21 #include <stdio.h>
22 #include <support/check.h>
23
24 static int
do_test(void)25 do_test (void)
26 {
27 iconv_t cd = iconv_open ("UTF-8//IGNORE", "EUC-KR");
28 TEST_VERIFY_EXIT (cd != (iconv_t) -1);
29
30 /* 0xfe (->0x7e : row 94) and 0xc9 (->0x49 : row 41) are user-defined
31 areas, which are not allowed and should be skipped over due to
32 //IGNORE. The trailing 0xfe also is an incomplete sequence, which
33 should be checked first. */
34 char input[4] = { '\xc9', '\xa1', '\0', '\xfe' };
35 char *inptr = input;
36 size_t insize = sizeof (input);
37 char output[4];
38 char *outptr = output;
39 size_t outsize = sizeof (output);
40
41 /* This used to crash due to buffer overrun. */
42 TEST_VERIFY (iconv (cd, &inptr, &insize, &outptr, &outsize) == (size_t) -1);
43 TEST_VERIFY (errno == EINVAL);
44 /* The conversion should produce one character, the converted null
45 character. */
46 TEST_VERIFY (sizeof (output) - outsize == 1);
47
48 TEST_VERIFY_EXIT (iconv_close (cd) != -1);
49
50 return 0;
51 }
52
53 #include <support/test-driver.c>
54