Skip to content

Copy setlocale() return value in case it gets clobbered by later calls #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

ntyni
Copy link

@ntyni ntyni commented Jun 17, 2019

Flagged by AddressSanitizer in [perl #134182]

Quoting IEEE Std 1003.1, 2004 Edition

https://pubs.opengroup.org/onlinepubs/009695399/functions/setlocale.html

The string returned by setlocale() is such that a subsequent call with
that string and its associated category shall restore that part of the
program's locale. The application shall not modify the string returned
which may be overwritten by a subsequent call to setlocale().

Bug: https://rt.perl.org/Public/Bug/Display.html?id=134182

Flagged by AddressSanitizer in [perl #134182]

Quoting IEEE Std 1003.1, 2004 Edition

 https://pubs.opengroup.org/onlinepubs/009695399/functions/setlocale.html

 The string returned by setlocale() is such that a subsequent call with
 that string and its associated category shall restore that part of the
 program's locale. The application shall not modify the string returned
 which may be overwritten by a subsequent call to setlocale().

Bug: https://rt.perl.org/Public/Bug/Display.html?id=134182
@tonycoz
Copy link
Contributor

tonycoz commented Sep 16, 2019

There's a more complete fix in https://rt.perl.org/Ticket/Display.html?id=134212

@Ark74
Copy link

Ark74 commented Feb 26, 2020

Hello, just stumbled on this and tested it out.
Using this patch still fails on ext/POSIX/t/mb :(

ext/POSIX/t/mb ................................................. # Failed test 2 - MB_CUR_MAX is at least 4 in a UTF-8 locale at ../../t/test.pl line 1074
#      got 'perl: warning: Setting locale failed.\nperl: warning: Please check that your locale settings:\n\tLANGUAGE = (unset),\n\tLC_ALL = (unset),\n\tLC_CTYPE = \"C.UTF-8\",\n\tLANG = \"es_MX.UTF-8\"\n    are supported and installed on your system.\nperl: warning: Falling back to the standard locale (\"C\").\n1'
# expected /(?^:[4-6])/
# PROG: 
# use POSIX; print &POSIX::MB_CUR_MAX
# STATUS: 0
# Failed test 3 - mblen() recognizes invalid multibyte characters at ../../t/test.pl line 1062
#      got "perl: warning: Setting locale failed.\nperl: warning: Please check that your locale settings:\n\tLANGUAGE = (unset),\n\tLC_ALL = (unset),\n\tLC_CTYPE = \"C.UTF-8\",\n\tLANG = \"es_MX.UTF-8\"\n    are supported and installed on your system.\nperl: warning: Falling back to the standard locale (\"C\").\n-1"
# expected "-1"
# PROG: 
# use POSIX; print &POSIX::mblen("�(", 2)
# STATUS: 0
# Failed test 4 - mblen() works on UTF-8 characters at ../../t/test.pl line 1062
#      got "perl: warning: Setting locale failed.\nperl: warning: Please check that your locale settings:\n\tLANGUAGE = (unset),\n\tLC_ALL = (unset),\n\tLC_CTYPE = \"C.UTF-8\",\n\tLANG = \"es_MX.UTF-8\"\n    are supported and installed on your system.\nperl: warning: Falling back to the standard locale (\"C\").\n-1"
# expected "2"
# PROG: 
# use POSIX; print &POSIX::mblen("\N{GREEK SMALL LETTER SIGMA}", 2)
# STATUS: 0
FAILED at test 2

[...]

Failed 1 test out of 2537, 99.96% okay.
	../ext/POSIX/t/mb.t

Env:

  • bionic - amd64
  • perl - 5.30.0-9
  • gdbm - 1.18.1-5
  • dist - 3.5-236-0.1build1
  • sbuild - 0.75.0-1ubuntu1

@Ark74
Copy link

Ark74 commented Feb 28, 2020

Weird enough after applying this along with Perl/perl5@69b89a0

The build process passed 👍

What am I missing here? 😕

@Leont
Copy link
Collaborator

Leont commented Jul 31, 2020

I've applied Tony's version of this patch

@Leont Leont closed this Jul 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants