From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 19511 invoked from network); 9 Feb 2022 17:57:26 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 9 Feb 2022 17:57:26 -0000 Received: (qmail 16314 invoked by uid 550); 9 Feb 2022 17:57:02 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 16282 invoked from network); 9 Feb 2022 17:57:01 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=4Uzocd17Aoro5r1ZU4vBRd0VyogbXFTPIy5xNKTFQag=; b=dacvlcAbyhlDUQwV78UE4h8S4HS8JPG8sewvOrCy7g88xSFw1sKEts15RYY64H0JTv Sx+PBFT5mMIxACiWYCY0B+Rw+q6BfQi7alIy6mJywmqhBelIWDnLlg1Rl77oXjgfHh7/ x1/FU2saV2+eLhgt1YQm5Lx64etXlNXj7j5Geyc13V1MMoqi8BZ6jwXmrwP/DQ2BadmB AiTG5aC5Jbw4eU6NXCuZlYBQgbeKrwr/QPnaFFxZz1yPrRFKwqZjQvOEDwfF9GiJseOY wp4DybMNCfVtveikBMXgZ8TuhicLPzrcN3vNMKKgD6tKhIwg8JGQ/ABjPKFFIf1xpfg6 AoXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=4Uzocd17Aoro5r1ZU4vBRd0VyogbXFTPIy5xNKTFQag=; b=UpKihWp/5ZmDOShpTDa7TEHCu+vOFNRBkoc+mLX4vsuw/8mhomH7ZadTbr8ffgPg26 xyrUnQTPPIPgsaJXo3/s6WB9EvHyBLmb8M21ZxsU8tXD5BSobDZZv1whytojkzwYQIKT k7kxPyTLayxuWXAXeLiEpFbocAlWBjR4tP2Mv8rhlhDJ600nhevDvKKtP2BpjrbCg2ed o0VPeFfE5okBrnG8DCiAC0tw3GXBKW5rEJlwlBNXhU1jTWkw2CU/AEpfCcH6wU4+l10m ED7cmlx1Dn6g+WPxagkUkfxsTyRXk1QaOIIZkeL/rE1UDqdK1God48iDa50qxBklcO3S Q4MA== X-Gm-Message-State: AOAM530azaE3KBVE3ImxGLwW4824dmF0GHLncEcZ+YTxyXaIJ6/0HAqr ErYcCYqyu4cCAZ9ukfnB83pv21lKD98= X-Google-Smtp-Source: ABdhPJxyjHISccUB3zyi0Au8axc7Ou+Wz94su/MeKMXByvhsru4QYqXhco8y2TxcCHBIlvG3WHDC0g== X-Received: by 2002:a05:6a00:1143:: with SMTP id b3mr3527603pfm.11.1644429407598; Wed, 09 Feb 2022 09:56:47 -0800 (PST) From: Pinghao Wu To: musl@lists.openwall.com Cc: Pinghao Wu Date: Thu, 10 Feb 2022 01:55:57 +0800 Message-Id: <20220209175557.25235-1-xdavidwuph@gmail.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [musl] [PATCH] fgetwc: fix errno when character span aver buffer end If attempt on converting character from buffer failed, errno is set to EILSEQ by mbtowc. As a result, if further byte-by-byte conversion succeeds, fgetwc will return a valid wchar with a misleading EILSEQ as errno. This fixes it by saving errno before the from buffer attempt, and restore if it fails. This also fixes fgetws which find the misleading EILSEQ and fails in this case. --- src/stdio/fgetwc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/stdio/fgetwc.c b/src/stdio/fgetwc.c index aa10b818..9dad0505 100644 --- a/src/stdio/fgetwc.c +++ b/src/stdio/fgetwc.c @@ -8,6 +8,7 @@ static wint_t __fgetwc_unlocked_internal(FILE *f) wchar_t wc; int c; size_t l; + int errno_save = errno; /* Convert character from buffer if possible */ if (f->rpos != f->rend) { @@ -16,6 +17,7 @@ static wint_t __fgetwc_unlocked_internal(FILE *f) f->rpos += l + !l; /* l==0 means 1 byte, null */ return wc; } + errno = errno_save; } /* Convert character byte-by-byte */ -- 2.35.1