develooper Front page | perl.perl5.porters | Postings from September 2019

[perl #133981] ext/XS-APItest/t/locale.t crashes on Windows afterpassing a couple tests

Thread Previous | Thread Next
From:
Steve Hay via RT
Date:
September 3, 2019 07:48
Subject:
[perl #133981] ext/XS-APItest/t/locale.t crashes on Windows afterpassing a couple tests
Message ID:
rt-4.0.24-20024-1567496928-1651.133981-15-0@perl.org
On Mon, 02 Sep 2019 18:03:28 -0700, tonyc wrote:
> On Sun, 18 Aug 2019 04:04:52 -0700, shay wrote:
> > On Thu, 15 Aug 2019 at 08:05, Steve Hay via RT
> > <perlbug-followup@perl.org> wrote:
> > >
> > > On Mon, 12 Aug 2019 22:49:19 -0700, tonyc wrote:
> > > > On Sat, 10 Aug 2019 05:53:14 -0700, shay wrote:
> > > > > The patch looks good to me, except that the second
> > > > >
> > > > > S_wrap_wsetlocale(aTHX_ category, locale);
> > > > >
> > > > > looks like it should be
> > > > >
> > > > > S_wrap_wsetlocale(aTHX_ categories[i], result);
> > > > >
> > > > > ?
> > > >
> > > > Updated patch attached.
> > > >
> > >
> > > You've changed category to categories[i], but not locale to result.
> > >
> > 
> > I've retested the updated patch with that extra change that you missed
> > too, and it is still passing all tests.
> 
> Thanks, I've applied it with that other fix and a shiny commit message
> as 6c3320363f6cd734c66a25852aac87e4f2538215.
> 

Your commit isn't quite what I was expecting. When I noted previously that "You've changed category to categories[i], but not locale to result" I meant that the second S_wrap_wsetlocale() call should be S_wrap_wsetlocale(aTHX_ categories[i], result) -- to match the arguments of the existing second setlocale() call, which was setlocale(categories[i], result).

Instead, you've left that S_wrap_wsetlocale() as S_wrap_wsetlocale(aTHX_ categories[i], locale) and changed the existing setlocale() call to setlocale(categories[i], locale). Did you mean to do that?

I've belatedly reproduced the failure in a small test program:

#include <stdio.h>
#include <locale.h>

int
main()
{
    const char * result = setlocale(LC_ALL, "Japanese");
    if (result == NULL) result = "NULL";
    fprintf(stderr, "%d: %s\n", __LINE__, result);

    result = setlocale(LC_ALL, "CatalĂ ");
    if (result == NULL) result = "NULL";
    fprintf(stderr, "%d: %s\n", __LINE__, result);
}

This prints:

9: Japanese_Japan.932

and then causes an invalid parameter exception to be raised. There is no invalid parameter handler in this program to deal with it, so the program crashes:

>	test.exe!_invoke_watson(const wchar_t * expression, const wchar_t * function_name, const wchar_t * file_name, unsigned int line_number, unsigned __int64 reserved) Line 224	C++
 	test.exe!_invalid_parameter(const wchar_t * const expression, const wchar_t * const function_name, const wchar_t * const file_name, const unsigned int line_number, const unsigned __int64 reserved) Line 112	C++
 	test.exe!_invalid_parameter_noinfo() Line 118	C++
 	test.exe!_mbstowcs_s_l(unsigned __int64 * pConvertedChars, wchar_t * pwcs, unsigned __int64 sizeInWords, const char * s, unsigned __int64 n, __crt_locale_pointers * plocinfo) Line 246	C++
 	test.exe!mbstowcs_s(unsigned __int64 * pConvertedChars, wchar_t * pwcs, unsigned __int64 sizeInWords, const char * s, unsigned __int64 n) Line 315	C++
 	[Inline Frame] test.exe!call_wsetlocale(const int category, const char * const narrow_locale)	C++
 	test.exe!setlocale::__l2::<lambda>() Line 41	C++
 	test.exe!__crt_seh_guarded_call<char *>::operator()<void <lambda>(void),char * <lambda>(void) &,void <lambda>(void) >(__acrt_lock_and_call::__l2::void <lambda>(void) && setup, setlocale::__l2::char * <lambda>(void) & action, __acrt_lock_and_call::__l2::void <lambda>(void) && cleanup) Line 204	C++
 	[Inline Frame] test.exe!__acrt_lock_and_call(const __acrt_lock_id)	C++
 	test.exe!setlocale(int _category, const char * _locale) Line 119	C++
 	test.exe!main() Line 11	C++

I don't think it's a(nother) CRT bug. It's just garbage-in garbage-out: We have successfully switched to Japanese locale and then use six bytes ("CatalĂ ") that aren't a valid Japanese encoding, so the CRT is correct to complain it's an invalid parameter.

The fix is to deal with the encoding correctly so as not to pass garbage in, which is hopefully what your patch takes care of.

---
via perlbug:  queue: perl5 status: pending release
https://rt.perl.org/Ticket/Display.html?id=133981

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About