NetBSD Problem Report #58615

From www@netbsd.org  Sat Aug 17 19:50:41 2024
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits)
	 client-signature RSA-PSS (2048 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id D5C141A9243
	for <gnats-bugs@gnats.NetBSD.org>; Sat, 17 Aug 2024 19:50:40 +0000 (UTC)
Message-Id: <20240817195039.A93461A9244@mollari.NetBSD.org>
Date: Sat, 17 Aug 2024 19:50:39 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: incomplete c8rtomb, c16rtomb handles NUL termination wrong
X-Send-Pr-Version: www-1.0

>Number:         58615
>Category:       lib
>Synopsis:       incomplete c8rtomb, c16rtomb handles NUL termination wrong
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    riastradh
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Aug 17 19:55:00 +0000 2024
>Last-Modified:  Sun Aug 18 02:20:02 +0000 2024
>Originator:     Taylor R Campbell
>Release:        current
>Organization:
The NetBS\0 Foundation
>Environment:
>Description:
C11 says of c16rtomb(3):

| If c16 is a null wide character, a null byte is stored, preceded by
| any shift sequence needed to restore the initial shift state; the
| resulting state described is the initial conversion state.

Likewise C23 of c8rtomb(3).

This seems to suggest that if an incomplete UTF-8 or UTF-16 sequence
is followed by a null, it should discard that incomplete sequence
(can't imagine anything else legitimate to do with it), optionally
output a shift sequence, and output a NUL byte.

However, our implementation -- and every other one I've looked at, in
OpenBSD, FreeBSD, and glibc -- fails with EILSEQ in this case and
produces no output.
>How-To-Repeat:
c16rtomb(buf, 0xd83d, &s);    /* should succeed and return 0 */
c16rtomb(buf, L'\0', &s);     /* should succeed, write one NUL byte to buf[0], and return 1 */
>Fix:
Yes, please!

>Release-Note:

>Audit-Trail:
From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/58615 CVS commit: src/tests/lib/libc/locale
Date: Sat, 17 Aug 2024 21:31:23 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Sat Aug 17 21:31:22 UTC 2024

 Modified Files:
 	src/tests/lib/libc/locale: t_c16rtomb.c t_c8rtomb.c

 Log Message:
 c8rtomb(3), c16rtomb(3): Add tests for incomplete NUL termination.

 PR lib/58615: incomplete c8rtomb, c16rtomb handles NUL termination
 wrong


 To generate a diff of this commit:
 cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/locale/t_c16rtomb.c \
     src/tests/lib/libc/locale/t_c8rtomb.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

Responsible-Changed-From-To: lib-bug-people->riastradh
Responsible-Changed-By: riastradh@NetBSD.org
Responsible-Changed-When: Sat, 17 Aug 2024 23:25:42 +0000
Responsible-Changed-Why:
I have an incoming fix soon


From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/58615 CVS commit: src
Date: Sun, 18 Aug 2024 02:19:35 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Sun Aug 18 02:19:35 UTC 2024

 Modified Files:
 	src/lib/libc/locale: c16rtomb.3 c16rtomb.c c32rtomb.3 c8rtomb.3
 	    c8rtomb.c
 	src/tests/lib/libc/locale: t_c16rtomb.c t_c8rtomb.c

 Log Message:
 c8rtomb(3), c16rtomb(3): Fix NUL handling.

 PR lib/58615: incomplete c8rtomb, c16rtomb handles NUL termination
 wrong


 To generate a diff of this commit:
 cvs rdiff -u -r1.7 -r1.8 src/lib/libc/locale/c16rtomb.3 \
     src/lib/libc/locale/c32rtomb.3
 cvs rdiff -u -r1.5 -r1.6 src/lib/libc/locale/c16rtomb.c \
     src/lib/libc/locale/c8rtomb.3
 cvs rdiff -u -r1.4 -r1.5 src/lib/libc/locale/c8rtomb.c
 cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/locale/t_c16rtomb.c \
     src/tests/lib/libc/locale/t_c8rtomb.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2024 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.