From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dmta1013.nifty.com (mta-snd01013.nifty.com [106.153.227.45]) by sourceware.org (Postfix) with ESMTPS id BAC433858D38 for ; Thu, 9 Nov 2023 10:26:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BAC433858D38 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=nifty.ne.jp Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=nifty.ne.jp ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BAC433858D38 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=106.153.227.45 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699525591; cv=none; b=lfMu+/UUfNImI04UKPKUkUStCld3qC7XDppR6ULstJc4GE1jB2kUzLUvvwM+hk6mFxg1EFvcl91fdcuGUY8uYaXDiaYRvYhqLgvu5Eb4th8zCIuAaThjcr8jVXK1U55kiicZVonXrRLGdEP3otqEXSMTgPE84nwPu5ydh1mq/9Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699525591; c=relaxed/simple; bh=t9NiDZf0jllSSgdP90htxNEllaR9ytlST/xmt2KszhE=; h=Date:From:To:Subject:Message-Id:Mime-Version; b=SRDbFnp/BeualK+a5V4c5vLZEwlXV2KVobtYWfYaBbALK0ALaioYGDEhPFUmqqNLcmJbzIEuXP+2A6CSTwXSBgY+7KTt8dhNRq2ETbJsh1qyfTr97zKZRf2O1F5eBO3pjes1IxxMtQ0c22bgHM2OWY76C5Qpd5/twu4nCPGhaDs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from HP-Z230 by dmta1013.nifty.com with ESMTP id <20231109102624344.OGHZ.71349.HP-Z230@nifty.com> for ; Thu, 9 Nov 2023 19:26:24 +0900 Date: Thu, 9 Nov 2023 19:26:24 +0900 From: Takashi Yano To: newlib@sourceware.org Subject: Re: [PATCH v5] newlib: libc: Fix crash on fprintf to a wide-oriented stream. Message-Id: <20231109192624.8fd1d42b4123b444b095f81f@nifty.ne.jp> In-Reply-To: References: <20231108214813.1569-1-takashi.yano@nifty.ne.jp> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00,KAM_DMARC_STATUS,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Thu, 9 Nov 2023 11:08:03 +0100 Corinna Vinschen wrote: > On Nov 9 06:48, Takashi Yano wrote: > > Previously, fprintf() on a wide-oriented stream crashes or outputs > > garbage. This is because a narrow char string which can be odd bytes > > in length is cast into a wide char string which should be even > > bytes in length in __sprint_r/__sfputs_r based on the __SWID flag. > > As a result, if the length is odd bytes, the reading buffer runs over > > the buffer length, which causes a crash. If the length is even bytes, > > garbage is printed. > > > > With this patch, any output to the stream which is set to different > > orientation fails with error just like glibc. Note that it behaves > > differently from other libc implementations such as BSD, musl and > > Solaris. > > > > Reviewed-by: Corinna Vinschen > > Signed-off-by: Takashi Yano > > --- > > newlib/libc/stdio/fgetwc.c | 6 ++++-- > > newlib/libc/stdio/fgetwc_u.c | 3 ++- > > newlib/libc/stdio/fgetws.c | 3 ++- > > newlib/libc/stdio/fputs.c | 9 ++++++--- > > newlib/libc/stdio/fputwc.c | 6 ++++-- > > newlib/libc/stdio/fputwc_u.c | 3 ++- > > newlib/libc/stdio/fputws.c | 6 ++++-- > > newlib/libc/stdio/fread.c | 7 ++++++- > > newlib/libc/stdio/fwrite.c | 9 +++++++-- > > newlib/libc/stdio/local.h | 31 +++++++++++++++++-------------- > > newlib/libc/stdio/putc.c | 4 ++++ > > newlib/libc/stdio/puts.c | 9 ++++++--- > > newlib/libc/stdio/refill.c | 3 ++- > > newlib/libc/stdio/ungetc.c | 6 +++++- > > newlib/libc/stdio/ungetwc.c | 5 +++-- > > newlib/libc/stdio/vfprintf.c | 5 ++++- > > newlib/libc/stdio/vfscanf.c | 6 +++++- > > newlib/libc/stdio/vfwprintf.c | 5 ++++- > > newlib/libc/stdio/vfwscanf.c | 6 +++++- > > 19 files changed, 92 insertions(+), 40 deletions(-) > > Looks good, please push. Thanks. Should this also be applied to cygwin-3_4-branch? -- Takashi Yano