From nobody@FreeBSD.org  Sat Feb 18 02:13:11 2006
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 7AC1A16A420
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 18 Feb 2006 02:13:11 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 2692C43D45
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 18 Feb 2006 02:13:11 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id k1I2DA5O037727
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 18 Feb 2006 02:13:10 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id k1I2DAA5037726;
	Sat, 18 Feb 2006 02:13:10 GMT
	(envelope-from nobody)
Message-Id: <200602180213.k1I2DAA5037726@www.freebsd.org>
Date: Sat, 18 Feb 2006 02:13:10 GMT
From: PauAmma <pauamma@gundo.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: lib/libc/locale/ldpart.c may cause lib/libc/locale/lmessages.c to ignore yesstr if nostr not specified
X-Send-Pr-Version: www-2.3

>Number:         93508
>Category:       kern
>Synopsis:       lib/libc/locale/ldpart.c may cause lib/libc/locale/lmessages.c to ignore yesstr if nostr not specified
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Feb 18 02:20:02 GMT 2006
>Closed-Date:    Sat Feb 18 22:00:38 GMT 2006
>Last-Modified:  Sat Feb 18 22:00:38 GMT 2006
>Originator:     PauAmma
>Release:        4.11 (likely present in 5.x and 6.x too)
>Organization:
Ecdysiasts United For Overdressing
>Environment:
N/A
>Description:
From lib/libc/locale/lmessages.c,v 1.14, function __messages_load_locale:

        if (ret == _LDP_LOADED) {
                if (_messages_locale.yesstr == NULL)
                        _messages_locale.yesstr = empty;
                if (_messages_locale.nostr == NULL)
                        _messages_locale.nostr = empty;
        }

This implies that yesstr and nostr can be left unspecified independently. However, lib/libc/locale/ldpart.c,v 1.15; function __part_load_locale has the following:

        num_lines = split_lines(p, plim);
        if (num_lines >= locale_buf_size_max)
                num_lines = locale_buf_size_max;
        else if (num_lines >= locale_buf_size_min)
                num_lines = locale_buf_size_min;
        else {
                errno = EFTYPE;
                goto bad_lbuf;
        }

Most callers of __part_load_locale pass the same value in locale_buf_size_max and locale_buf_size_min, but __messages_load_locale passes 4 and 2, respectively (as far as I can tell from reading the source). This means that if some, but not all, of the optional lines are present in the locale file, the lines that are present will be ignored (or reset to their default value) by the following code (later in __part_load_locale):

        for (i = num_lines; i < locale_buf_size_max; i++)
                dst_localebuf[i] = NULL;

This is inconsistent with __messages_load_locale, which allows yesstr (line 3, counting from 1) to be specified even if nostr isn't.
>How-To-Repeat:
Use locale ro_RO.ISO8859-2 or ro_RO.UTF-8. (For some reason, LC_MESSAGES has 3 lines for those locales.)
>Fix:
In __part_load_locale, change:

        else if (num_lines >= locale_buf_size_min)
                num_lines = locale_buf_size_min;
        else {
                errno = EFTYPE;
                goto bad_lbuf;
        }

to:

         else if (num_lines <= locale_buf_size_min) {
                errno = EFTYPE;
                goto bad_lbuf;
        }

Note: not tested at all.
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: ache 
State-Changed-When: Sat Feb 18 21:57:31 UTC 2006 
State-Changed-Why:  
This is compatiblity stuff from times when no yesstr/nostr fields exists. 
yesstr not supposed to be specified without nostr. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=93508 
>Unformatted:
