From owner-freebsd-bugs@FreeBSD.ORG Fri Jan 29 19:40:11 2010 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E814E10656ED for ; Fri, 29 Jan 2010 19:40:10 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id D45948FC1D for ; Fri, 29 Jan 2010 19:40:09 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id o0TJe9QK022821 for ; Fri, 29 Jan 2010 19:40:09 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id o0TJe9sQ022818; Fri, 29 Jan 2010 19:40:09 GMT (envelope-from gnats) Resent-Date: Fri, 29 Jan 2010 19:40:09 GMT Resent-Message-Id: <201001291940.o0TJe9sQ022818@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Corinna Vinschen Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 53086106568D for ; Fri, 29 Jan 2010 19:32:52 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21]) by mx1.freebsd.org (Postfix) with ESMTP id E74368FC0A for ; Fri, 29 Jan 2010 19:32:51 +0000 (UTC) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o0TJWpK4003205 for ; Fri, 29 Jan 2010 19:32:51 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.3/8.14.3/Submit) id o0TJWpRK003204; Fri, 29 Jan 2010 19:32:51 GMT (envelope-from nobody) Message-Id: <201001291932.o0TJWpRK003204@www.freebsd.org> Date: Fri, 29 Jan 2010 19:32:51 GMT From: Corinna Vinschen To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: misc/143350: pointer comparison against '\0' in strfmon.c X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Jan 2010 19:40:11 -0000 >Number: 143350 >Category: misc >Synopsis: pointer comparison against '\0' in strfmon.c >Confidential: no >Severity: serious >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Jan 29 19:40:09 UTC 2010 >Closed-Date: >Last-Modified: >Originator: Corinna Vinschen >Release: CVS HEAD >Organization: Cygwin >Environment: >Description: There appears to be a bug in strfom.c, function __setup_vars. When the value for the negative sign string is fetched, there are two comparisons of the following style: *signstr = (lc->negative_sign == '\0') ? "-" : lc->negative_sign; lc->negative_sign is a string pointer. The above statement compares the pointer against '\0'. This looks like a typo. Actually the comparison should check if the first character in lc->negative_sign is \0, or better, if lc->negative_sign is an empty string. A check for NULL doesn't make sense since localeconv never returns NULL pointers as struct lconv members. So I think the patch below should be the right way to go. Corinna >How-To-Repeat: >Fix: Index: strfmon.c =================================================================== RCS file: /home/ncvs/src/lib/libc/stdlib/strfmon.c,v retrieving revision 1.19 diff -u -p -r1.19 strfmon.c --- strfmon.c 24 Apr 2008 07:49:00 -0000 1.19 +++ strfmon.c 29 Jan 2010 19:23:39 -0000 @@ -413,7 +413,7 @@ __setup_vars(int flags, char *cs_precede *cs_precedes = lc->int_n_cs_precedes; *sep_by_space = lc->int_n_sep_by_space; *sign_posn = (flags & PARENTH_POSN) ? 0 : lc->int_n_sign_posn; - *signstr = (lc->negative_sign == '\0') ? "-" + *signstr = (*lc->negative_sign == '\0') ? "-" : lc->negative_sign; } else if (flags & USE_INTL_CURRENCY) { *cs_precedes = lc->int_p_cs_precedes; @@ -424,7 +424,7 @@ __setup_vars(int flags, char *cs_precede *cs_precedes = lc->n_cs_precedes; *sep_by_space = lc->n_sep_by_space; *sign_posn = (flags & PARENTH_POSN) ? 0 : lc->n_sign_posn; - *signstr = (lc->negative_sign == '\0') ? "-" + *signstr = (*lc->negative_sign == '\0') ? "-" : lc->negative_sign; } else { *cs_precedes = lc->p_cs_precedes; >Release-Note: >Audit-Trail: >Unformatted: