NetBSD Problem Report #54414
From www@netbsd.org Sat Jul 27 22:59:53 2019
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id 873C37A149
for <gnats-bugs@gnats.NetBSD.org>; Sat, 27 Jul 2019 22:59:53 +0000 (UTC)
Message-Id: <20190727225952.72BE17A1D3@mollari.NetBSD.org>
Date: Sat, 27 Jul 2019 22:59:52 +0000 (UTC)
From: uwe@stderr.spb.ru
Reply-To: uwe@stderr.spb.ru
To: gnats-bugs@NetBSD.org
Subject: wcsrtombs(3) doesn't update the source argument on conversion error
X-Send-Pr-Version: www-1.0
>Number: 54414
>Category: lib
>Synopsis: wcsrtombs(3) doesn't update the source argument on conversion error
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: lib-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sat Jul 27 23:00:00 +0000 2019
>Last-Modified: Sun Jul 28 14:30:01 +0000 2019
>Originator: Valery Ushakov
>Release: NetBSD-8
>Organization:
>Environment:
>Description:
wcsrtombs(3) definition in C99 says:
[#3] If dst is not a null pointer, the pointer object
pointed to by src is assigned either a null pointer (if
conversion stopped due to reaching a terminating null wide
character) or the address just past the last wide character
converted (if any).
Our wcsrtombs(3) does NOT update its src (pwcs) parameter if it
encounters a conversion error.
>How-To-Repeat:
#include <wchar.h>
#include <string.h>
#include <stdio.h>
#if !defined(__arraycount)
#define __arraycount(a) (sizeof(a)/sizeof(a[0]))
#endif
int
main()
{
wchar_t label[] = L"L" L"\u0403" L"bel";
char lbuf[128] = { 0 };
mbstate_t mbstate;
size_t n;
memset(&mbstate, 0, sizeof(mbstate));
const wchar_t *wp = label;
n = wcsrtombs(lbuf, &wp, sizeof(lbuf), &mbstate);
if (n == (size_t)-1) {
printf("%p %p\n", label, wp);
}
memset(&mbstate, 0, sizeof(mbstate));
char *dst = lbuf;
for (int i = 0; i < __arraycount(label); ++i) {
wchar_t wc = label[i];
n = wcrtomb(dst, wc, &mbstate);
if (n == (size_t)-1) {
printf("failed to convert \\x%x at %d\n", wc, i);
break;
}
dst += n;
}
return 0;
}
On Linux I get, e.g.:
0x7fff71f762e0 0x7fff71f762e4
failed to convert \x403 at 1
on NetBSD
0xffffe148 0xffffe148
failed to convert \x403 at 1
>Fix:
>Audit-Trail:
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/54414 CVS commit: src/tests/lib/libc/locale
Date: Sun, 28 Jul 2019 09:46:45 -0400
Module Name: src
Committed By: christos
Date: Sun Jul 28 13:46:45 UTC 2019
Modified Files:
src/tests/lib/libc/locale: Makefile
Added Files:
src/tests/lib/libc/locale: t_wcsrtombs.c
Log Message:
PR/54414: Valery Ushakov: add a test for wcsrtombs(3) doesn't update the
source argument on conversion error
To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/tests/lib/libc/locale/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/locale/t_wcsrtombs.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/54414 CVS commit: src/lib/libc/citrus
Date: Sun, 28 Jul 2019 09:52:24 -0400
Module Name: src
Committed By: christos
Date: Sun Jul 28 13:52:24 UTC 2019
Modified Files:
src/lib/libc/citrus: citrus_none.c
Log Message:
PR/54414: Valery Ushakov: c99 requires that wcsrtombs(3) updates the source
argument on conversion error
To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/lib/libc/citrus/citrus_none.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/54414 CVS commit: src/lib/libc/citrus
Date: Sun, 28 Jul 2019 10:26:08 -0400
Module Name: src
Committed By: christos
Date: Sun Jul 28 14:26:08 UTC 2019
Modified Files:
src/lib/libc/citrus: citrus_ctype_template.h
Log Message:
PR/54414: Valery Ushakov: c99 requires that wcsrtombs(3) updates the source
argument on conversion error
To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/lib/libc/citrus/citrus_ctype_template.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
(Contact us)
$NetBSD: query-full-pr,v 1.43 2018/01/16 07:36:43 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.