git-iconv-Preserve-iconv-c-error-exit-on-invalid-inputs-
authorGNU Libc Maintainers <debian-glibc@lists.debian.org>
Sat, 23 Nov 2024 13:57:03 +0000 (14:57 +0100)
committerAurelien Jarno <aurel32@debian.org>
Sat, 23 Nov 2024 13:57:03 +0000 (14:57 +0100)
commit847d317ac8392fc93d2430d469e7479320d97c03
treeb48ff5338677bdb04cb07a6e761d669c204c8a45
parent3c82f261486d082a6801512d6c377824d1b119cb
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