NetBSD Problem Report #59067

From www@netbsd.org  Tue Feb 11 02:39:33 2025
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) server-digest SHA256
	 client-signature RSA-PSS (2048 bits) client-digest SHA256)
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id D8F041A923A
	for <gnats-bugs@gnats.NetBSD.org>; Tue, 11 Feb 2025 02:39:32 +0000 (UTC)
Message-Id: <20250211023931.78DA81A923C@mollari.NetBSD.org>
Date: Tue, 11 Feb 2025 02:39:31 +0000 (UTC)
From: ru_j217@aliyun.com
Reply-To: ru_j217@aliyun.com
To: gnats-bugs@NetBSD.org
Subject: wctrans got error member.
X-Send-Pr-Version: www-1.0

>Number:         59067
>Category:       lib
>Synopsis:       wctrans got error member.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          needs-pullups
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Feb 11 02:40:00 +0000 2025
>Closed-Date:    
>Last-Modified:  Mon Jul 20 21:50:28 +0000 2026
>Originator:     rujin
>Release:        trunk
>Organization:
ACOINFO
>Environment:
NetBSD 10.1 NetBSD 10.1(GENERIC) #0: Mon Dec 16 13.08:11 UTC 2024 mkrepro@mkrepro.NetBSD.org:/usr/src/sys/arch/amd64/compile/GENERIC amd64
>Description:
wctrans got error member make a crash on running.
>How-To-Repeat:
use this code:

#include <stdio.h>
#include <wchar.h>
#include <locale.h>
#include <wctype.h>
#include <wchar.h>

int main()
{
    printf("set locale: %s\n", setlocale(LC_ALL, ""));

    wchar_t wc = L'A'; 
    wctrans_t lower = wctrans("towlower"); 

    // crash on this line
    wchar_t res = towctrans(wc, lower);

    if (res != WEOF) {
        printf("wc: %lc, res: %lc\n", wc, res);
    } else {
        printf("test failed!\n");
    }

    return 0;
}
>Fix:
https://github.com/NetBSD/src/blob/trunk/lib/libc/locale/iswctype_mb.c 

line 132 update to:

return (wctrans_t)__UNCONST(&rl->rl_wctype[i]);  

  =====>  

return (wctrans_t)__UNCONST(&rl->rl_wctrans[i]);

>Release-Note:

>Audit-Trail:
From: Thomas Klausner <wiz@NetBSD.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: lib/59067: wctrans got error member.
Date: Tue, 11 Feb 2025 07:44:40 +0100

 On Tue, Feb 11, 2025 at 02:40:00AM +0000, ru_j217@aliyun.com wrote:
 > wctrans got error member make a crash on running.

 I didn't see an error when I tried your test program on NetBSD
 10.99.12/x86_64. Where did you get a crash? What was the backtrace?

 However, you should really check the return value of wctrans, the man
 page says:

 RETURN VALUES
      wctrans() returns:

      0             If the string charmap does not corresponding to a valid
                    character mapping name.

 (There's a typo, it should be "tolower", not "towlower".)

 #include <stdio.h>
 #include <wchar.h>
 #include <locale.h>
 #include <wctype.h>

 int main()
 {
     printf("set locale: %s\n", setlocale(LC_ALL, ""));

     wchar_t wc = L'A';
     wctrans_t lower = wctrans("towlower");
     if (lower == 0) {
 	printf("wctrans failed\n");
 	return 1;
     }

     // crash on this line
     wchar_t res = towctrans(wc, lower);

     if (res != WEOF) {
         printf("wc: %lc, res: %lc\n", wc, res);
     } else {
         printf("test failed!\n");
     }

     return 0;
 }

  Thomas

From: RVP <rvp@SDF.ORG>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: lib/59067: wctrans got error member.
Date: Wed, 26 Feb 2025 07:38:34 +0000 (UTC)

 > >Fix:
 > https://github.com/NetBSD/src/blob/trunk/lib/libc/locale/iswctype_mb.c
 > 
 > line 132 update to:
 > 
 > return (wctrans_t)__UNCONST(&rl->rl_wctype[i]);
 >
 >   =====>
 > 
 > return (wctrans_t)__UNCONST(&rl->rl_wctrans[i]);
 >

 Yah, I think this is correct, but, there's one additional fix needed for this
 to work in the "C"/"POSIX" locale too. So, we now have:


 ---START patch---
 diff -urN a/src/lib/libc/locale/iswctype_mb.c b/src/lib/libc/locale/iswctype_mb.c
 --- a/src/lib/libc/locale/iswctype_mb.c	2024-06-07 22:20:47.236031995 +0000
 +++ b/src/lib/libc/locale/iswctype_mb.c	2025-02-12 11:38:55.548531035 +0000
 @@ -129,7 +129,7 @@
   	for (i = 0; i < _WCTRANS_NINDEXES; ++i) {
   		_DIAGASSERT(rl->rl_wctrans[i].te_name != NULL);
   		if (!strcmp(rl->rl_wctrans[i].te_name, charmap))
 -			return (wctrans_t)__UNCONST(&rl->rl_wctype[i]);
 +			return (wctrans_t)__UNCONST(&rl->rl_wctrans[i]);
   	}
   	return (wctrans_t)NULL;
   }
 diff -urN a/src/lib/libc/locale/runetable.c b/src/lib/libc/locale/runetable.c
 --- a/src/lib/libc/locale/runetable.c	2013-08-18 20:03:48.000000000 +0000
 +++ b/src/lib/libc/locale/runetable.c	2025-02-12 11:45:11.254300802 +0000
 @@ -320,11 +320,11 @@
       "646",
       &_citrus_ctype_default,
       {
 -	{   "towlower",
 +	{   "tolower",
   	    __UNCONST(&_DefaultRuneLocale.rl_maplower[0]),
   	    __UNCONST(&_DefaultRuneLocale.rl_maplower_ext)
   	},
 -	{   "towupper",
 +	{   "toupper",
   	    __UNCONST(&_DefaultRuneLocale.rl_mapupper[0]),
   	    __UNCONST(&_DefaultRuneLocale.rl_mapupper_ext)
   	},
 ---END patch---

 Should be pulled up to -9, and -10.

 -RVP

From: RVP <rvp@SDF.ORG>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: lib/59067: wctrans got error member.
Date: Wed, 8 Jul 2026 22:48:54 +0000 (UTC)

 On Wed, 26 Feb 2025, RVP via gnats wrote:

 > > >Fix:
 > > https://github.com/NetBSD/src/blob/trunk/lib/libc/locale/iswctype_mb.c
 > >
 > > line 132 update to:
 > >
 > > return (wctrans_t)__UNCONST(&rl->rl_wctype[i]);
 > >
 > >   =====>
 > >
 > > return (wctrans_t)__UNCONST(&rl->rl_wctrans[i]);
 > >
 >
 > Yah, I think this is correct, but, there's one additional fix needed for this
 > to work in the "C"/"POSIX" locale too. So, we now have:
 >
 >
 > ---START patch---
 > diff -urN a/src/lib/libc/locale/iswctype_mb.c b/src/lib/libc/locale/iswctype_mb.c
 > --- a/src/lib/libc/locale/iswctype_mb.c	2024-06-07 22:20:47.236031995 +0000
 > +++ b/src/lib/libc/locale/iswctype_mb.c	2025-02-12 11:38:55.548531035 +0000
 > @@ -129,7 +129,7 @@
 >   	for (i = 0; i < _WCTRANS_NINDEXES; ++i) {
 >   		_DIAGASSERT(rl->rl_wctrans[i].te_name != NULL);
 >   		if (!strcmp(rl->rl_wctrans[i].te_name, charmap))
 > -			return (wctrans_t)__UNCONST(&rl->rl_wctype[i]);
 > +			return (wctrans_t)__UNCONST(&rl->rl_wctrans[i]);
 >   	}
 >   	return (wctrans_t)NULL;
 >   }
 > diff -urN a/src/lib/libc/locale/runetable.c b/src/lib/libc/locale/runetable.c
 > --- a/src/lib/libc/locale/runetable.c	2013-08-18 20:03:48.000000000 +0000
 > +++ b/src/lib/libc/locale/runetable.c	2025-02-12 11:45:11.254300802 +0000
 > @@ -320,11 +320,11 @@
 >       "646",
 >       &_citrus_ctype_default,
 >       {
 > -	{   "towlower",
 > +	{   "tolower",
 >   	    __UNCONST(&_DefaultRuneLocale.rl_maplower[0]),
 >   	    __UNCONST(&_DefaultRuneLocale.rl_maplower_ext)
 >   	},
 > -	{   "towupper",
 > +	{   "toupper",
 >   	    __UNCONST(&_DefaultRuneLocale.rl_mapupper[0]),
 >   	    __UNCONST(&_DefaultRuneLocale.rl_mapupper_ext)
 >   	},
 > ---END patch---
 >
 > Should be pulled up to -9, and -10.
 >

 This is an easy fix. Bump!

 -RVP

From: "Robert Elz" <kre@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59067 CVS commit: src/lib/libc/locale
Date: Fri, 10 Jul 2026 06:48:54 +0000

 Module Name:	src
 Committed By:	kre
 Date:		Fri Jul 10 06:48:54 UTC 2026

 Modified Files:
 	src/lib/libc/locale: iswctype_mb.c runetable.c

 Log Message:
 PR lib/59067 (wctrans got error member)

 Patches from the OP (ru_j217) and from RVP - see the PR

 This looks to be just correcting what appear to be simple
 errors in the code.

 XXX pullup -11


 To generate a diff of this commit:
 cvs rdiff -u -r1.14 -r1.15 src/lib/libc/locale/iswctype_mb.c
 cvs rdiff -u -r1.29 -r1.30 src/lib/libc/locale/runetable.c

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

State-Changed-From-To: open->pending-pullups
State-Changed-By: kre@NetBSD.org
State-Changed-When: Sun, 19 Jul 2026 19:38:30 +0000
State-Changed-Why:
[pullup-11 #388]


From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59067 CVS commit: [netbsd-11] src/lib/libc/locale
Date: Mon, 20 Jul 2026 08:52:03 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Mon Jul 20 08:52:03 UTC 2026

 Modified Files:
 	src/lib/libc/locale [netbsd-11]: iswctype_mb.c runetable.c

 Log Message:
 Pull up following revision(s) (requested by kre in ticket #388):

 	lib/libc/locale/runetable.c: revision 1.30
 	lib/libc/locale/iswctype_mb.c: revision 1.15

 PR lib/59067 (wctrans got error member)

 Patches from the OP (ru_j217) and from RVP - see the PR

 This looks to be just correcting what appear to be simple
 errors in the code.


 To generate a diff of this commit:
 cvs rdiff -u -r1.14 -r1.14.4.1 src/lib/libc/locale/iswctype_mb.c
 cvs rdiff -u -r1.29 -r1.29.40.1 src/lib/libc/locale/runetable.c

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

State-Changed-From-To: pending-pullups->needs-pullups
State-Changed-By: kre@NetBSD.org
State-Changed-When: Mon, 20 Jul 2026 21:50:28 +0000
State-Changed-Why:
Need to check for -10 pullup, -11 done.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.