Blame iconvdata/bug-iconv13.c

Packit Service 5dea78
/* bug 24973: Test EUC-KR module
Packit Service 5dea78
   Copyright (C) 2020 Free Software Foundation, Inc.
Packit Service 5dea78
   This file is part of the GNU C Library.
Packit Service 5dea78
Packit Service 5dea78
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 5dea78
   modify it under the terms of the GNU Lesser General Public
Packit Service 5dea78
   License as published by the Free Software Foundation; either
Packit Service 5dea78
   version 2.1 of the License, or (at your option) any later version.
Packit Service 5dea78
Packit Service 5dea78
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 5dea78
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 5dea78
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 5dea78
   Lesser General Public License for more details.
Packit Service 5dea78
Packit Service 5dea78
   You should have received a copy of the GNU Lesser General Public
Packit Service 5dea78
   License along with the GNU C Library; if not, see
Packit Service 5dea78
   <https://www.gnu.org/licenses/>.  */
Packit Service 5dea78
Packit Service 5dea78
#include <errno.h>
Packit Service 5dea78
#include <iconv.h>
Packit Service 5dea78
#include <stdio.h>
Packit Service 5dea78
#include <support/check.h>
Packit Service 5dea78
Packit Service 5dea78
static int
Packit Service 5dea78
do_test (void)
Packit Service 5dea78
{
Packit Service 5dea78
  iconv_t cd = iconv_open ("UTF-8//IGNORE", "EUC-KR");
Packit Service 5dea78
  TEST_VERIFY_EXIT (cd != (iconv_t) -1);
Packit Service 5dea78
Packit Service 5dea78
  /* 0xfe (->0x7e : row 94) and 0xc9 (->0x49 : row 41) are user-defined
Packit Service 5dea78
     areas, which are not allowed and should be skipped over due to
Packit Service 5dea78
     //IGNORE.  The trailing 0xfe also is an incomplete sequence, which
Packit Service 5dea78
     should be checked first.  */
Packit Service 5dea78
  char input[4] = { '\xc9', '\xa1', '\0', '\xfe' };
Packit Service 5dea78
  char *inptr = input;
Packit Service 5dea78
  size_t insize = sizeof (input);
Packit Service 5dea78
  char output[4];
Packit Service 5dea78
  char *outptr = output;
Packit Service 5dea78
  size_t outsize = sizeof (output);
Packit Service 5dea78
Packit Service 5dea78
  /* This used to crash due to buffer overrun.  */
Packit Service 5dea78
  TEST_VERIFY (iconv (cd, &inptr, &insize, &outptr, &outsize) == (size_t) -1);
Packit Service 5dea78
  TEST_VERIFY (errno == EINVAL);
Packit Service 5dea78
  /* The conversion should produce one character, the converted null
Packit Service 5dea78
     character.  */
Packit Service 5dea78
  TEST_VERIFY (sizeof (output) - outsize == 1);
Packit Service 5dea78
Packit Service 5dea78
  TEST_VERIFY_EXIT (iconv_close (cd) != -1);
Packit Service 5dea78
Packit Service 5dea78
  return 0;
Packit Service 5dea78
}
Packit Service 5dea78
Packit Service 5dea78
#include <support/test-driver.c>