git-iconv-Preserve-iconv-c-error-exit-on-invalid-inputs-
authorGNU Libc Maintainers <debian-glibc@lists.debian.org>
Tue, 24 Sep 2024 19:46:16 +0000 (21:46 +0200)
committerAurelien Jarno <aurel32@debian.org>
Tue, 24 Sep 2024 19:46:16 +0000 (21:46 +0200)
commitc93c5cc229e2cba294d611620666b1408c3c7a6d
tree196c177f892568d6f4c77db6bbea547e4e83a82b
parentb3b4f83a394462ff12a1d2e264f2378714333c8b
git-iconv-Preserve-iconv-c-error-exit-on-invalid-inputs-

commit 53ed84fee1647db907d40d36fd4294add6d9279f
Author: Florian Weimer <fweimer@redhat.com>
Date:   Fri Sep 20 13:10:54 2024 +0200

    iconv: Preserve iconv -c error exit on invalid inputs (bug 32046)

    In several converters, a __GCONV_ILLEGAL_INPUT result gets overwritten
    with __GCONV_FULL_OUTPUT.  As a result, iconv (the function) returns
    E2BIG instead of EILSEQ.  The iconv program does not see the original
    EILSEQ failure, does not recognize the invalid input, and may
    incorrectly exit successfully.

    To address this, a new __flags bit is used to indicate a sticky input
    error state.  All __GCONV_ILLEGAL_INPUT results are replaced with a
    function call that sets this new __GCONV_ENCOUNTERED_ILLEGAL_INPUT and
    returns __GCONV_ILLEGAL_INPUT.  The iconv program checks for
    __GCONV_ENCOUNTERED_ILLEGAL_INPUT and overrides the exit status.

    The converter changes introducing __gconv_mark_illegal_input are
    mostly mechanical, except for the res variable initialization in
    iconvdata/iso-2022-jp.c: this error gets overwritten with __GCONV_OK
    and other results in the following code.  If res ==
    __GCONV_ILLEGAL_INPUT afterwards, STANDARD_TO_LOOP_ERR_HANDLER below
    will handle it.

    The __gconv_mark_illegal_input changes do not alter the errno value
    set by the iconv function.  This is simpler to implement than
    reviewing each __GCONV_FULL_OUTPUT result and adjust it not to
    override a previous __GCONV_ILLEGAL_INPUT result.  Doing it that way
    would also change some E2BIG errors in to EILSEQ errors, so it had to
    be done conditionally (under a flag set by the iconv program only), to
    avoid confusing buffer management in other applications.

Reviewed-by: DJ Delorie <dj@redhat.com>
Gbp-Pq: Topic any
Gbp-Pq: Name git-iconv-Preserve-iconv-c-error-exit-on-invalid-inputs-.patch
16 files changed:
iconv/Makefile
iconv/gconv_int.h
iconv/gconv_simple.c
iconv/gconv_trans.c
iconv/iconv_prog.c
iconv/loop.c
iconv/tst-iconv-sticky-input-error.c [new file with mode: 0644]
iconv/tst-iconv_prog-buffer.sh
iconvdata/cp932.c
iconvdata/euc-jp-ms.c
iconvdata/gbbig5.c
iconvdata/ibm1364.c
iconvdata/iso646.c
iconvdata/unicode.c
iconvdata/utf-16.c
iconvdata/utf-32.c