NetBSD Problem Report #51670

From www@NetBSD.org  Tue Nov 29 09:44:51 2016
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 "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id D2CDB7A2FD
	for <gnats-bugs@gnats.NetBSD.org>; Tue, 29 Nov 2016 09:44:50 +0000 (UTC)
Message-Id: <20161129094449.C37DF7A31E@mollari.NetBSD.org>
Date: Tue, 29 Nov 2016 09:44:49 +0000 (UTC)
From: carsten.kunze@arcor.de
Reply-To: carsten.kunze@arcor.de
To: gnats-bugs@NetBSD.org
Subject: curses: printw displays multibyte string wrong if ASAN is not used
X-Send-Pr-Version: www-1.0

>Number:         51670
>Category:       lib
>Synopsis:       curses: printw displays multibyte string wrong if ASAN is not used
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Nov 29 09:45:00 +0000 2016
>Last-Modified:  Sun Dec 04 06:55:00 +0000 2016
>Originator:     Carsten Kunze
>Release:        NetBSD 7.99.42 (GENERIC.201611250700Z) amd64
>Organization:
>Environment:
NetBSD 7.99.42 (GENERIC.201611250700Z) amd64
>Description:
printw() does output multibyte strings only correctly when compiled with ASAN.  This likely indicates a curses internal data corruption which has no effect with the different memory layout used by ASAN.
>How-To-Repeat:
Below a Makefile and a C file is shown.

The output is "äöü" when compiled with the comment in the Makefile and "" without the comment.

$ cat Makefile                                                                                                                                                                                 
LDFLAGS=-lcurses
CFLAGS=-g #-fsanitize=address

all: main

clean:
        rm -f main

$ cat main.c                                                                                                                                                                                   
#include <locale.h>
#include <curses.h>

int
main()
{
        char *mbs = "";

        setlocale(LC_ALL, "");
        initscr();
        printw("%s\n", mbs);
        refresh();
        getch();
        endwin();
        return 0;
}


>Fix:

>Audit-Trail:
From: David Holland <dholland-bugs@netbsd.org>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: lib/51670: curses: printw displays multibyte string wrong if
 ASAN is not used
Date: Tue, 29 Nov 2016 23:55:27 +0000

 On Tue, Nov 29, 2016 at 09:45:00AM +0000, carsten.kunze@arcor.de wrote:
  >         char *mbs = "";

 I've received several copies of this through various paths and tools
 (lists, gnats, etc.) and ~all of them have mangled this string
 differently. (It would be funny, except it's not really.)

 What's it supposed to be in hex?

 -- 
 David A. Holland
 dholland@netbsd.org

From: christos@zoulas.com (Christos Zoulas)
To: gnats-bugs@NetBSD.org, lib-bug-people@netbsd.org, 
	gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, carsten.kunze@arcor.de
Cc: 
Subject: Re: lib/51670: curses: printw displays multibyte string wrong if ASAN is not used
Date: Tue, 29 Nov 2016 20:27:06 -0500

 On Nov 30, 12:00am, dholland-bugs@netbsd.org (David Holland) wrote:
 -- Subject: Re: lib/51670: curses: printw displays multibyte string wrong if 

 | The following reply was made to PR lib/51670; it has been noted by GNATS.
 | 
 | From: David Holland <dholland-bugs@netbsd.org>
 | To: gnats-bugs@NetBSD.org
 | Cc: 
 | Subject: Re: lib/51670: curses: printw displays multibyte string wrong if
 |  ASAN is not used
 | Date: Tue, 29 Nov 2016 23:55:27 +0000
 | 
 |  On Tue, Nov 29, 2016 at 09:45:00AM +0000, carsten.kunze@arcor.de wrote:
 |   >         char *mbs = "";
 |  
 |  I've received several copies of this through various paths and tools
 |  (lists, gnats, etc.) and ~all of them have mangled this string
 |  differently. (It would be funny, except it's not really.)
 |  
 |  What's it supposed to be in hex?

 "\xef\xbf\xbd\xef\xbf\xbd"

 The problem is sanitizer=address intercepts dlopen incorrectly.
 I'll post a fix on tech-userlevel. Static libc reproduces the problem
 with a different code path.

 christos

From: Carsten Kunze <carsten.kunze@arcor.de>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: lib/51670: curses: printw displays multibyte string wrong if
 ASAN is not used
Date: Sun, 4 Dec 2016 07:52:09 +0100 (CET)

 Tested, solution is working.

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.