public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug localedata/12788] New: [PATCH] setlocale sets the locale of LC_ALL incorrect to 'C' in some cases (/when LC_CTYPE is used)
@ 2011-05-20  8:01 bug_rh at spam dot wizbit.be
  2011-05-21  6:08 ` [Bug localedata/12788] " drepper.fsp at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: bug_rh at spam dot wizbit.be @ 2011-05-20  8:01 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=12788

           Summary: [PATCH] setlocale sets the locale of LC_ALL incorrect
                    to 'C' in some cases (/when LC_CTYPE is used)
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: localedata
        AssignedTo: libc-locales@sources.redhat.com
        ReportedBy: bug_rh@spam.wizbit.be


Created attachment 5739
  --> http://sourceware.org/bugzilla/attachment.cgi?id=5739
patch - update the condition in set_composite_name

There is a bug in setlocale that can result in LC_ALL being incorrectly set to
LC_ALL.

Test case:

$ cat bug-setlocale.c 
#include <stdio.h>
#include <locale.h>

int main () {
        printf("setlocale(LC_ALL, \"\") = %s\n", setlocale(LC_ALL, ""));
        printf("setlocale(LC_CTYPE, \"\") = %s\n", setlocale(LC_CTYPE, ""));
        printf("setlocale(LC_ALL, NULL) = %s\n", setlocale(LC_ALL, NULL));
        printf("setlocale(LC_NUMERIC, \"\") = %s\n", setlocale(LC_NUMERIC,
""));
        printf("setlocale(LC_ALL, NULL) = %s\n", setlocale(LC_ALL, NULL));

        setlocale(LC_ALL, "C"); 
        printf("setlocale(LC_ALL, NULL) = %s\n", setlocale(LC_ALL, NULL));
        printf("setlocale(LC_CTYPE, NULL) = %s\n", setlocale(LC_CTYPE, NULL));
}


Running it:

$ env -i LC_CTYPE=en_US ./bug-setlocale
setlocale(LC_ALL, "") = LC_CTYPE=en_US;LC_NUMERIC=C;LC_....  # => expected
setlocale(LC_CTYPE, "") = en_US                              # => expected
setlocale(LC_ALL, NULL) = LC_CTYPE=en_US;LC_NUMERIC=C;LC_... # => expected
setlocale(LC_NUMERIC, "") = C                                # => expected
setlocale(LC_ALL, NULL) = C                                  # => not expected;
expected value: LC_CTYPE=en_US;LC_NUMERIC=C;LC_...
setlocale(LC_ALL, NULL) = C                                  # => expected
setlocale(LC_CTYPE, NULL) = en_US                            # => not expected;
expected value: 'C'


Important when running the test case:
a) the locale en_US needs to be installed/needs to exists on the system
b) only the environment variable LC_CTYPE should be set (LC_ALL, LANG,
LC_COLLATE, LC_MESSAGES, LC_MONETARY, LC_NUMERIC, LC_TIME need to be unset)

I traced the problem to the file locale/setlocale.c, function:
new_composite_name, line: 150-160:

  for (i = 0; i < __LC_LAST; ++i)
    if (i != LC_ALL)
      {
        const char *name = (category == LC_ALL ? newnames[i] :
                            category == i ? newnames[0] :
                            _nl_global_locale.__names[i]);
        last_len = strlen (name);
        cumlen += _nl_category_name_sizes[i] + 1 + last_len + 1;
        if (i > 0 && same && strcmp (name, newnames[0]) != 0)
          same = 0;
      }

The problem is the condition on line 158: the  'i > 0'  is incorrect.
The condition should be: ((category == LC_ALL && i > 0) || (category != LC_ALL
&& i != category))


The reasoning/the explanation (using the above test case):

A) setlocale(LC_ALL, ""):

This calls new_composite_name with category = 6 and newnames an array of 13
elements.
For i = 0: name = newnames[0]  => strcmp(name, newnames[0]) != 0  can be
skipped
For i = 1: name = newnames[1]  => strcmp(name, newnames[1]) != 0  can not be
skipped

B) setlocale(LC_CTYPE, "")

This calls new_composite_name with category = 0 and newnames an array of 1
element

For i = 0: name = newnames[0]  => strcmp(name, newnames[0]) != 0  can be
skipped
For i = 1: name = _nl_global_locale.__names[1]  => strcmp(name, newnames[0]) !=
0  can not be skipped


C) setlocale(LC_NUMERIC, "")

This calls new_composite_name with category = 1 and newnames an array of 1
element

For i = 0: name = _nl_global_locale.__names[0]  => strcmp(name, newnames[0]) !=
0  can not be skipped
For i = 1: name = newnames[0] => strcmp(name, newnames[0]) != 0  can be skipped



==> strcmp(name, newnames[0]) != 0 can only be skipped if:

* category == LC_ALL and i == 0
* category != LC_ALL and i == category



The bug was (I believe) introduced in commit
4b10dd6c1959577f57850ca427a94fe22b9f3299 (dated Tue, 31 Aug 1999 07:04:41 +0000
(07:04 +0000))


Attached is a patch which updates the condition.


The output after the patch:

$ env -i LC_CTYPE=en_US ./bug-setlocale
setlocale(LC_ALL, "") =
LC_CTYPE=en_US;LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=C;LC_PAPER=C;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C;LC_IDENTIFICATION=C
setlocale(LC_CTYPE, "") = en_US
setlocale(LC_ALL, NULL) =
LC_CTYPE=en_US;LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=C;LC_PAPER=C;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C;LC_IDENTIFICATION=C
setlocale(LC_NUMERIC, "") = C
setlocale(LC_ALL, NULL) =
LC_CTYPE=en_US;LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=C;LC_PAPER=C;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C;LC_IDENTIFICATION=C
setlocale(LC_ALL, NULL) = C
setlocale(LC_CTYPE, NULL) = C

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug localedata/12788] [PATCH] setlocale sets the locale of LC_ALL incorrect to 'C' in some cases (/when LC_CTYPE is used)
  2011-05-20  8:01 [Bug localedata/12788] New: [PATCH] setlocale sets the locale of LC_ALL incorrect to 'C' in some cases (/when LC_CTYPE is used) bug_rh at spam dot wizbit.be
@ 2011-05-21  6:08 ` drepper.fsp at gmail dot com
  2014-02-16 17:43 ` jackie.rosen at hushmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: drepper.fsp at gmail dot com @ 2011-05-21  6:08 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=12788

Ulrich Drepper <drepper.fsp at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |drepper.fsp at gmail dot
                   |                            |com
         Resolution|                            |FIXED

--- Comment #1 from Ulrich Drepper <drepper.fsp at gmail dot com> 2011-05-21 06:08:13 UTC ---
I've check in a simpler patch.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug localedata/12788] [PATCH] setlocale sets the locale of LC_ALL incorrect to 'C' in some cases (/when LC_CTYPE is used)
  2011-05-20  8:01 [Bug localedata/12788] New: [PATCH] setlocale sets the locale of LC_ALL incorrect to 'C' in some cases (/when LC_CTYPE is used) bug_rh at spam dot wizbit.be
  2011-05-21  6:08 ` [Bug localedata/12788] " drepper.fsp at gmail dot com
@ 2014-02-16 17:43 ` jackie.rosen at hushmail dot com
  2014-05-28 19:44 ` schwab at sourceware dot org
  2014-06-27 13:19 ` fweimer at redhat dot com
  3 siblings, 0 replies; 5+ messages in thread
From: jackie.rosen at hushmail dot com @ 2014-02-16 17:43 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=12788

Jackie Rosen <jackie.rosen at hushmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jackie.rosen at hushmail dot com

--- Comment #2 from Jackie Rosen <jackie.rosen at hushmail dot com> ---
*** Bug 260998 has been marked as a duplicate of this bug. ***
Seen from the domain http://volichat.com
Page where seen: http://volichat.com/adult-chat-rooms
Marked for reference. Resolved as fixed @bugzilla.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug localedata/12788] [PATCH] setlocale sets the locale of LC_ALL incorrect to 'C' in some cases (/when LC_CTYPE is used)
  2011-05-20  8:01 [Bug localedata/12788] New: [PATCH] setlocale sets the locale of LC_ALL incorrect to 'C' in some cases (/when LC_CTYPE is used) bug_rh at spam dot wizbit.be
  2011-05-21  6:08 ` [Bug localedata/12788] " drepper.fsp at gmail dot com
  2014-02-16 17:43 ` jackie.rosen at hushmail dot com
@ 2014-05-28 19:44 ` schwab at sourceware dot org
  2014-06-27 13:19 ` fweimer at redhat dot com
  3 siblings, 0 replies; 5+ messages in thread
From: schwab at sourceware dot org @ 2014-05-28 19:44 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=12788

Andreas Schwab <schwab at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|jackie.rosen at hushmail dot com   |

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug localedata/12788] [PATCH] setlocale sets the locale of LC_ALL incorrect to 'C' in some cases (/when LC_CTYPE is used)
  2011-05-20  8:01 [Bug localedata/12788] New: [PATCH] setlocale sets the locale of LC_ALL incorrect to 'C' in some cases (/when LC_CTYPE is used) bug_rh at spam dot wizbit.be
                   ` (2 preceding siblings ...)
  2014-05-28 19:44 ` schwab at sourceware dot org
@ 2014-06-27 13:19 ` fweimer at redhat dot com
  3 siblings, 0 replies; 5+ messages in thread
From: fweimer at redhat dot com @ 2014-06-27 13:19 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=12788

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
              Flags|                            |security-

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-06-27 13:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-20  8:01 [Bug localedata/12788] New: [PATCH] setlocale sets the locale of LC_ALL incorrect to 'C' in some cases (/when LC_CTYPE is used) bug_rh at spam dot wizbit.be
2011-05-21  6:08 ` [Bug localedata/12788] " drepper.fsp at gmail dot com
2014-02-16 17:43 ` jackie.rosen at hushmail dot com
2014-05-28 19:44 ` schwab at sourceware dot org
2014-06-27 13:19 ` fweimer at redhat dot com

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 read-only IMAP folder(s) and NNTP newsgroup(s).