git-iconv-Preserve-iconv-c-error-exit-on-invalid-inputs-
authorGNU Libc Maintainers <debian-glibc@lists.debian.org>
Fri, 3 Jan 2025 10:56:38 +0000 (11:56 +0100)
committerAurelien Jarno <aurel32@debian.org>
Fri, 3 Jan 2025 10:56:38 +0000 (11:56 +0100)
commit0a35d45e2e534c5990a6b3cb5fdf339fbc5dc380
tree52f0d49bb3def8b855a0c01377e97c0623a1c86e
parent812cb51d9c1d9c9b18277a4f588e099a83e9af13
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