mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: Assaf Gordon <assafgordon@gmail.com>
Cc: musl@lists.openwall.com
Subject: Re: Possible bug in setlocale upon invalid LC_ALL value
Date: Fri, 1 Apr 2016 20:58:58 -0400	[thread overview]
Message-ID: <20160402005858.GA21636@brightrain.aerifal.cx> (raw)
In-Reply-To: <4C4AEBC7-4344-4867-B8F6-F1A691F123E0@gmail.com>

On Fri, Apr 01, 2016 at 08:47:01PM -0400, Assaf Gordon wrote:
> Hello musl developers,
> 
> I'm testing compilation of GNU coreutils on Alpine Linux 3.3.3 (linux kernel 4.1.20, musl-1.1.12-r3).
> 
> I think I've encountered a problem in musl, where using setlocale with invalid locale name returns the invalid locale instead of a known locale.
> example:
> 
>    $ LC_ALL=missing ./myprogram
> 
> If myprogram calls setlocale(LC_ALL,""),
> then musl sets the internal locale despite being invalid value.
> later, checking the locale for a specific category (e.g. LC_COLLATE) will return 'missing' instead of 'C' .
> 
> 
> The relevant POSIX clause is this:
>  http://pubs.opengroup.org/onlinepubs/9699919799/functions/setlocale.html
>  "[...] If the value of any of these environment variable searches yields a locale that
>   is not supported (and non-null), setlocale() shall return a null pointer and the global
>   locale shall not be changed."
> 
> Below is a short C program demonstrating the issue, with example output from various OSes.

This is intentional. All locale names are valid under musl, and those
which don't have any particular definition are just aliases for
C.UTF-8. The alternative would be that UTF-8 support breaks whenever
LC_* vars are set but locales are not installed/configured, which
would pretty much _always_ be the case when running a static-linked
standalone binary on a non-musl-based system (where LC_* are probably
set to something the main host libc recognizes).

One possibility if this behavior is problematic would be to only
consider names without their own definitions as aliases for C.UTF-8
when MUSL_LOCPATH is not set. However I think we'd need to see a
strong motivation for doing that, since it seems like it would be
worse behavior in some ways, especially when using LC_MESSAGES set to
a language for which you don't have a locale installed.

Rich


  reply	other threads:[~2016-04-02  0:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-02  0:47 Assaf Gordon
2016-04-02  0:58 ` Rich Felker [this message]
2016-04-02  2:46   ` Assaf Gordon
2016-04-02  4:09     ` Rich Felker
2016-04-02  4:18       ` Assaf Gordon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160402005858.GA21636@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=assafgordon@gmail.com \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).