develooper Front page | perl.perl5.porters | Postings from June 2012

[perl #113536] GetEnvironmentStrings() mess up the values for non-ascii strings

Thread Previous | Thread Next
From:
Karthik Rajagopalan
Date:
June 6, 2012 15:17
Subject:
[perl #113536] GetEnvironmentStrings() mess up the values for non-ascii strings
Message ID:
rt-3.6.HEAD-5009-1339019990-5.113536-75-0@perl.org
# New Ticket Created by  Karthik Rajagopalan 
# Please include the string:  [perl #113536]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=113536 >


Hi,

Before launching a sub-process using win32_spawnvp of win32.c, we try
to get the environment block of the parent process by
PerlEnv_get_children. This is defined to call CreateChildEnv(.)->
CreateLocalEnvironmentStrings(..), which reside in perlhost.h file of
win32 directory. This in turn call kernel32.dll's
GetEnvironmentStrings(..). The ansi version of the function return the
strings
in OEM code page. So this mess up the string while passing to the
subprocess if it has non-ascii characters. The patch attached ( wrt
main branch 5.17  ) address the issue by calling
GetEnvironmentStringsW(..) and convert the strings to ANSI encoding in
a single shot. It is then used to construct the new environment block
for the sub-process.

You will observe this issue in all versions of perl including 5.17 of
your main branch.

To reproduce the issue, following the below recipe -

0) Create a user account in windows with non-ascii character, say bærbar
1) Open a cmd shell with this special usename account.
2) Download test1.c, test.bat.txt, test.pl to a directory, say X
3) cd to X.
4) rename test.bat.txt test.bat
5) Run vcvcars32.bat or vcvars64.bat to get Visual Studio environment
( I used VS 2010 to compile it )
6) Run test.bat. This will give test1.exe binary.
7) Set your perl environment in PATH and run perl test.pl

The program should successfully launch test1.exe and get the
CSIDL_LOCAL_APPDATA of the user. Since the USERNAME, USERPROFILE env
get messed up at perl side, you won't be able to retrieve the
CSIDL_LOCAL_APPDATA of the user. With the patch, the program should
successfully retrieve the value.

The ANSI code page of my system while doing this test is
'windows-1252' and OEM code page is 'IBM437'.

My System Details
----------------------------
---
Flags:
    category=core
    severity=critical
---
Site configuration information for perl 5.14.2:

Configured by rajagopa at Wed May 23 12:48:29 2012.

Summary of my perl5 (revision 5 version 14 subversion 2) configuration:

  Platform:
    osname=MSWin32, osvers=6.1, archname=MSWin32-x64-multi-thread
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cl', ccflags ='-nologo -GF -W3 -MD -Zi -DNDEBUG -Ox -GL
-fp:precise -DWIN32 -D_CONSOLE -DNO_STRICT -DWIN64 -DCONSERVATIVE
-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE
-DPERL_TEXTMODE_SCRIPTS -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS
-DUSE_PERLIO',
    optimize='-MD -Zi -DNDEBUG -Ox -GL -fp:precise',
    cppflags='-DWIN32'
    ccversion='16.00.30319.01', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=8
    ivtype='__int64', ivsize=8, nvtype='double', nvsize=8,
Off_t='__int64', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='link', ldflags ='-nologo -nodefaultlib -debug -opt:ref,icf
-ltcg  -libpath:"c:\perl\lib\CORE"  -machine:AMD64
"/manifestdependency:type='Win32'
name='Microsoft.Windows.Common-Controls' version='6.0.0.0'
processorArchitecture='*' publicKeyToken='6595b64144ccf1df'
language='*'"'
    libpth=\lib
    libs=oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib
netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib  version.lib
odbc32.lib odbccp32.lib comctl32.lib msvcrt.lib
    perllibs=oldnames.lib kernel32.lib user32.lib gdi32.lib
winspool.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib
oleaut32.lib  netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib
version.lib odbc32.lib odbccp32.lib comctl32.lib msvcrt.lib
    libc=msvcrt.lib, so=dll, useshrplib=true, libperl=perl514.lib
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -debug
-opt:ref,icf -ltcg  -libpath:"c:\perl\lib\CORE"  -machine:AMD64
"/manifestdependency:type='Win32'
name='Microsoft.Windows.Common-Controls' version='6.0.0.0'
processorArchitecture='*' publicKeyToken='6595b64144ccf1df'
language='*'"'

Locally applied patches:


---
@INC for perl 5.14.2:
    c:/msys/1.0/software/lib/Windows-x64/VS2010/perl-5.14.2/site/lib
    c:/msys/1.0/software/lib/Windows-x64/VS2010/perl-5.14.2/lib
    .

---
Environment for perl 5.14.2:
    HOME (unset)
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=c:\msys\1.0\software\lib\Windows-x64\VS2010\perl-5.14.2\bin;C:\Program
Files (x86)\Microsoft Visual Studio
10.0\VC\BIN\amd64;C:\Windows\Microsoft.NET\Framework64\v4.0.30319;C:\Windows\Microsoft.NET\Framework64\v3.5;C:\Program
Files (x86)\Microsoft Visual Studio 10.0\VC\VCPackages;C:\Program
Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE;C:\Program Files
(x86)\Microsoft Visual Studio 10.0\Common7\Tools;C:\Program Files
(x86)\HTML Help Workshop;C:\Program Files (x86)\Microsoft Visual
Studio 10.0\Team Tools\Performance Tools\x64;C:\Program Files
(x86)\Microsoft Visual Studio 10.0\Team Tools\Performance
Tools;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\NETFX
4.0 Tools\x64;C:\Program Files (x86)\Microsoft
SDKs\Windows\v7.0A\bin\x64;C:\Program Files (x86)\Microsoft
SDKs\Windows\v7.0A\bin;C:\Program Files (x86)\Windows Resource
Kits\Tools\;C:\Program Files
(x86)\Intel\Compiler\11.1\065\lib\Intel64;C:\Program Files
(x86)\Intel\Compiler\11.1\065\lib\ia32;C:\Program Files
(x86)\Intel\Compiler\11.1\065\mkl\em64t\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;c:\Program
Files (x86)\Microsoft SQL Server\90\Tools\binn\;C:\Program
Files\Microsoft Windows Performance Toolkit\;C:\Program Files
(x86)\AMD\CodeAnalyst\bin
    PERL_BADLANG (unset)
    SHELL (unset)

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