Skip to content

Commit 95f2d79

Browse files
committed
Update Win32 to CPAN version 0.53
[DELTA] 0.53 [2019-08-05] - improve Win32::GetOSDisplayName - added Win2016/2019 detection and version information by Richard Leach [PR/15] - Include wchar.h to allow building with g++ by Tony Cook [rt#127836] 0.52_02 [2018-11-02] by Reini Urban - added () usage croaks. - Fixed a -Warray-bounds buffer overflow in LONGPATH, - Fix various -Wunused warnings and two -Wmaybe-uninitialized. 0.52_01 [2017-11-30] - add missing const
1 parent 5de6cd7 commit 95f2d79

File tree

4 files changed

+71
-23
lines changed

4 files changed

+71
-23
lines changed

Porting/Maintainers.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,7 @@ package Maintainers;
12441244
},
12451245

12461246
'Win32' => {
1247-
'DISTRIBUTION' => "JDB/Win32-0.52.tar.gz",
1247+
'DISTRIBUTION' => "JDB/Win32-0.53.tar.gz",
12481248
'FILES' => q[cpan/Win32],
12491249
},
12501250

cpan/Win32/Win32.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package Win32;
88
require DynaLoader;
99

1010
@ISA = qw|Exporter DynaLoader|;
11-
$VERSION = '0.52';
11+
$VERSION = '0.53';
1212
$XS_VERSION = $VERSION;
1313
$VERSION = eval $VERSION;
1414

cpan/Win32/Win32.xs

Lines changed: 68 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#define WIN32_LEAN_AND_MEAN
2+
#include <wchar.h>
23
#include <wctype.h>
34
#include <windows.h>
45
#include <shlobj.h>
6+
#include <wchar.h>
57

68
#define PERL_NO_GET_CONTEXT
79
#include "EXTERN.h"
@@ -114,7 +116,7 @@ typedef void (WINAPI *PFNGetNativeSystemInfo)(LPSYSTEM_INFO lpSystemInfo);
114116
* WORD type has been replaced by unsigned short because
115117
* WORD is already used by Perl itself.
116118
*/
117-
struct {
119+
struct g_osver_t {
118120
DWORD dwOSVersionInfoSize;
119121
DWORD dwMajorVersion;
120122
DWORD dwMinorVersion;
@@ -126,7 +128,7 @@ struct {
126128
unsigned short wSuiteMask;
127129
BYTE wProductType;
128130
BYTE wReserved;
129-
} g_osver = {0, 0, 0, 0, 0, "", 0, 0, 0, 0, 0};
131+
} g_osver = {0, 0, 0, 0, 0, "", 0, 0, 0, 0, 0};
130132
BOOL g_osver_ex = TRUE;
131133

132134
#define ONE_K_BUFSIZE 1024
@@ -201,7 +203,7 @@ wstr_to_sv(pTHX_ WCHAR *wstr)
201203
* characters for the characters not in the ANSI codepage.
202204
*/
203205
SV*
204-
get_unicode_env(pTHX_ WCHAR *name)
206+
get_unicode_env(pTHX_ const WCHAR *name)
205207
{
206208
SV *sv = NULL;
207209
void *env;
@@ -377,6 +379,7 @@ get_childenv(void)
377379
void
378380
free_childenv(void *d)
379381
{
382+
PERL_UNUSED_ARG(d);
380383
}
381384

382385
# define PerlDir_mapA(dir) (dir)
@@ -388,7 +391,7 @@ XS(w32_ExpandEnvironmentStrings)
388391
dXSARGS;
389392

390393
if (items != 1)
391-
croak("usage: Win32::ExpandEnvironmentStrings($String);\n");
394+
croak("usage: Win32::ExpandEnvironmentStrings($String)");
392395

393396
if (IsWin2000()) {
394397
WCHAR value[31*1024];
@@ -536,7 +539,7 @@ XS(w32_LookupAccountName)
536539

537540
if (items != 5)
538541
croak("usage: Win32::LookupAccountName($system, $account, $domain, "
539-
"$sid, $sidtype);\n");
542+
"$sid, $sidtype)");
540543

541544
SIDLen = sizeof(SID);
542545
DomLen = sizeof(Domain);
@@ -570,7 +573,7 @@ XS(w32_LookupAccountSID)
570573
BOOL bResult;
571574

572575
if (items != 5)
573-
croak("usage: Win32::LookupAccountSID($system, $sid, $account, $domain, $sidtype);\n");
576+
croak("usage: Win32::LookupAccountSID($system, $sid, $account, $domain, $sidtype)");
574577

575578
sid = SvPV_nolen(ST(1));
576579
if (IsValidSid(sid)) {
@@ -601,7 +604,7 @@ XS(w32_InitiateSystemShutdown)
601604

602605
if (items != 5)
603606
croak("usage: Win32::InitiateSystemShutdown($machineName, $message, "
604-
"$timeOut, $forceClose, $reboot);\n");
607+
"$timeOut, $forceClose, $reboot)");
605608

606609
machineName = SvPV_nolen(ST(0));
607610

@@ -642,7 +645,7 @@ XS(w32_AbortSystemShutdown)
642645
char *machineName;
643646

644647
if (items != 1)
645-
croak("usage: Win32::AbortSystemShutdown($machineName);\n");
648+
croak("usage: Win32::AbortSystemShutdown($machineName)");
646649

647650
machineName = SvPV_nolen(ST(0));
648651

@@ -680,7 +683,7 @@ XS(w32_MsgBox)
680683
I32 result;
681684

682685
if (items < 1 || items > 3)
683-
croak("usage: Win32::MsgBox($message [, $flags [, $title]]);\n");
686+
croak("usage: Win32::MsgBox($message [, $flags [, $title]])");
684687

685688
if (items > 1)
686689
flags = (DWORD)SvIV(ST(1));
@@ -696,7 +699,7 @@ XS(w32_MsgBox)
696699
Safefree(title);
697700
}
698701
else {
699-
char *title = "Perl";
702+
const char *title = "Perl";
700703
char *msg = SvPV_nolen(ST(0));
701704
if (items > 2)
702705
title = SvPV_nolen(ST(2));
@@ -787,6 +790,8 @@ XS(w32_UnregisterServer)
787790
XS(w32_GetArchName)
788791
{
789792
dXSARGS;
793+
if (items)
794+
Perl_croak(aTHX_ "usage: Win32::GetArchName()");
790795
XSRETURN_PV(getenv("PROCESSOR_ARCHITECTURE"));
791796
}
792797

@@ -796,6 +801,8 @@ XS(w32_GetChipName)
796801
SYSTEM_INFO sysinfo;
797802
HMODULE module;
798803
PFNGetNativeSystemInfo pfnGetNativeSystemInfo;
804+
if (items)
805+
Perl_croak(aTHX_ "usage: Win32::GetChipName()");
799806

800807
Zero(&sysinfo,1,SYSTEM_INFO);
801808
module = GetModuleHandle("kernel32.dll");
@@ -814,8 +821,11 @@ XS(w32_GuidGen)
814821
dXSARGS;
815822
GUID guid;
816823
char szGUID[50] = {'\0'};
817-
HRESULT hr = CoCreateGuid(&guid);
824+
HRESULT hr;
825+
if (items)
826+
Perl_croak(aTHX_ "usage: Win32::GuidGen()");
818827

828+
hr = CoCreateGuid(&guid);
819829
if (SUCCEEDED(hr)) {
820830
LPOLESTR pStr = NULL;
821831
#ifdef __cplusplus
@@ -896,7 +906,7 @@ XS(w32_GetFolderPath)
896906
SV *sv;
897907
HKEY hkey;
898908
HKEY root = HKEY_CURRENT_USER;
899-
WCHAR *name = NULL;
909+
const WCHAR *name = NULL;
900910

901911
switch (folder) {
902912
case CSIDL_ADMINTOOLS: name = L"Administrative Tools"; break;
@@ -997,7 +1007,7 @@ XS(w32_GetFileVersion)
9971007
char *data;
9981008

9991009
if (items != 1)
1000-
croak("usage: Win32::GetFileVersion($filename)\n");
1010+
croak("usage: Win32::GetFileVersion($filename)");
10011011

10021012
filename = SvPV_nolen(ST(0));
10031013
size = GetFileVersionInfoSize(filename, &handle);
@@ -1048,16 +1058,22 @@ XS(w32_SetChildShowWindow)
10481058
* inside the thread_intern structure, the MSWin32 implementation
10491059
* lives in win32/win32.c in the core Perl distribution.
10501060
*/
1051-
dXSARGS;
1061+
dSP;
1062+
I32 ax = POPMARK;
1063+
EXTEND(SP,1);
10521064
XSRETURN_UNDEF;
10531065
}
10541066
#endif
10551067

10561068
XS(w32_GetCwd)
10571069
{
10581070
dXSARGS;
1071+
char* ptr;
1072+
if (items)
1073+
Perl_croak(aTHX_ "usage: Win32::GetCwd()");
1074+
10591075
/* Make the host for current directory */
1060-
char* ptr = PerlEnv_get_childdir();
1076+
ptr = PerlEnv_get_childdir();
10611077
/*
10621078
* If ptr != Nullch
10631079
* then it worked, set PV valid,
@@ -1108,6 +1124,8 @@ XS(w32_GetNextAvailDrive)
11081124
char ix = 'C';
11091125
char root[] = "_:\\";
11101126

1127+
if (items)
1128+
Perl_croak(aTHX_ "usage: Win32::GetNextAvailDrive()");
11111129
EXTEND(SP,1);
11121130
while (ix <= 'Z') {
11131131
root[0] = ix++;
@@ -1122,6 +1140,8 @@ XS(w32_GetNextAvailDrive)
11221140
XS(w32_GetLastError)
11231141
{
11241142
dXSARGS;
1143+
if (items)
1144+
Perl_croak(aTHX_ "usage: Win32::GetLastError()");
11251145
EXTEND(SP,1);
11261146
XSRETURN_IV(GetLastError());
11271147
}
@@ -1138,6 +1158,8 @@ XS(w32_SetLastError)
11381158
XS(w32_LoginName)
11391159
{
11401160
dXSARGS;
1161+
if (items)
1162+
Perl_croak(aTHX_ "usage: Win32::LoginName()");
11411163
EXTEND(SP,1);
11421164
if (IsWin2000()) {
11431165
WCHAR name[128];
@@ -1164,6 +1186,8 @@ XS(w32_NodeName)
11641186
dXSARGS;
11651187
char name[MAX_COMPUTERNAME_LENGTH+1];
11661188
DWORD size = sizeof(name);
1189+
if (items)
1190+
Perl_croak(aTHX_ "usage: Win32::NodeName()");
11671191
EXTEND(SP,1);
11681192
if (GetComputerName(name,&size)) {
11691193
/* size does NOT include NULL :-( */
@@ -1178,9 +1202,11 @@ XS(w32_DomainName)
11781202
{
11791203
dXSARGS;
11801204
HMODULE module = LoadLibrary("netapi32.dll");
1181-
PFNNetApiBufferFree pfnNetApiBufferFree;
1182-
PFNNetWkstaGetInfo pfnNetWkstaGetInfo;
1205+
PFNNetApiBufferFree pfnNetApiBufferFree = NULL;
1206+
PFNNetWkstaGetInfo pfnNetWkstaGetInfo = NULL;
11831207

1208+
if (items)
1209+
Perl_croak(aTHX_ "usage: Win32::DomainName()");
11841210
if (module) {
11851211
GETPROC(NetApiBufferFree);
11861212
GETPROC(NetWkstaGetInfo);
@@ -1242,8 +1268,10 @@ XS(w32_FsType)
12421268
dXSARGS;
12431269
char fsname[256];
12441270
DWORD flags, filecomplen;
1271+
if (items)
1272+
Perl_croak(aTHX_ "usage: Win32::FsType()");
12451273
if (GetVolumeInformation(NULL, NULL, 0, NULL, &filecomplen,
1246-
&flags, fsname, sizeof(fsname))) {
1274+
&flags, fsname, sizeof(fsname))) {
12471275
if (GIMME_V == G_ARRAY) {
12481276
XPUSHs(sv_2mortal(newSVpvn(fsname,strlen(fsname))));
12491277
XPUSHs(sv_2mortal(newSViv(flags)));
@@ -1260,6 +1288,8 @@ XS(w32_FsType)
12601288
XS(w32_GetOSVersion)
12611289
{
12621290
dXSARGS;
1291+
if (items)
1292+
Perl_croak(aTHX_ "usage: Win32::GetOSVersion()");
12631293

12641294
if (GIMME_V == G_SCALAR) {
12651295
XSRETURN_IV(g_osver.dwPlatformId);
@@ -1282,13 +1312,17 @@ XS(w32_GetOSVersion)
12821312
XS(w32_IsWinNT)
12831313
{
12841314
dXSARGS;
1315+
if (items)
1316+
Perl_croak(aTHX_ "usage: Win32::IsWinNT()");
12851317
EXTEND(SP,1);
12861318
XSRETURN_IV(IsWinNT());
12871319
}
12881320

12891321
XS(w32_IsWin95)
12901322
{
12911323
dXSARGS;
1324+
if (items)
1325+
Perl_croak(aTHX_ "usage: Win32::IsWin95()");
12921326
EXTEND(SP,1);
12931327
XSRETURN_IV(IsWin95());
12941328
}
@@ -1364,6 +1398,8 @@ XS(w32_GetTickCount)
13641398
{
13651399
dXSARGS;
13661400
DWORD msec = GetTickCount();
1401+
if (items)
1402+
Perl_croak(aTHX_ "usage: Win32::GetTickCount()");
13671403
EXTEND(SP,1);
13681404
if ((IV)msec > 0)
13691405
XSRETURN_IV(msec);
@@ -1525,7 +1561,7 @@ XS(w32_GetLongPathName)
15251561
WCHAR wide_path[MAX_PATH+1];
15261562
WCHAR *long_path;
15271563

1528-
if (wcslen(wstr) < countof(wide_path)) {
1564+
if (wcslen(wstr) < (size_t)countof(wide_path)) {
15291565
wcscpy(wide_path, wstr);
15301566
long_path = my_longpathW(wide_path);
15311567
if (long_path) {
@@ -1619,13 +1655,17 @@ XS(w32_OutputDebugString)
16191655
XS(w32_GetCurrentProcessId)
16201656
{
16211657
dXSARGS;
1658+
if (items)
1659+
Perl_croak(aTHX_ "usage: Win32::GetCurrentProcessId()");
16221660
EXTEND(SP,1);
16231661
XSRETURN_IV(GetCurrentProcessId());
16241662
}
16251663

16261664
XS(w32_GetCurrentThreadId)
16271665
{
16281666
dXSARGS;
1667+
if (items)
1668+
Perl_croak(aTHX_ "usage: Win32::GetCurrentThreadId()");
16291669
EXTEND(SP,1);
16301670
XSRETURN_IV(GetCurrentThreadId());
16311671
}
@@ -1713,27 +1753,35 @@ XS(w32_GetProductInfo)
17131753
XS(w32_GetACP)
17141754
{
17151755
dXSARGS;
1756+
if (items)
1757+
Perl_croak(aTHX_ "usage: Win32::GetACP()");
17161758
EXTEND(SP,1);
17171759
XSRETURN_IV(GetACP());
17181760
}
17191761

17201762
XS(w32_GetConsoleCP)
17211763
{
17221764
dXSARGS;
1765+
if (items)
1766+
Perl_croak(aTHX_ "usage: Win32::GetConsoleCP()");
17231767
EXTEND(SP,1);
17241768
XSRETURN_IV(GetConsoleCP());
17251769
}
17261770

17271771
XS(w32_GetConsoleOutputCP)
17281772
{
17291773
dXSARGS;
1774+
if (items)
1775+
Perl_croak(aTHX_ "usage: Win32::GetConsoleOutputCP()");
17301776
EXTEND(SP,1);
17311777
XSRETURN_IV(GetConsoleOutputCP());
17321778
}
17331779

17341780
XS(w32_GetOEMCP)
17351781
{
17361782
dXSARGS;
1783+
if (items)
1784+
Perl_croak(aTHX_ "usage: Win32::GetOEMCP()");
17371785
EXTEND(SP,1);
17381786
XSRETURN_IV(GetOEMCP());
17391787
}
@@ -1764,7 +1812,7 @@ PROTOTYPES: DISABLE
17641812

17651813
BOOT:
17661814
{
1767-
char *file = __FILE__;
1815+
const char *file = __FILE__;
17681816

17691817
if (g_osver.dwOSVersionInfoSize == 0) {
17701818
g_osver.dwOSVersionInfoSize = sizeof(g_osver);

cpan/Win32/longpath.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ LONGPATH(CHAR_T *path)
8181
*start = sep;
8282
if (fhand != INVALID_HANDLE_VALUE) {
8383
STRLEN len = FN_STRLEN(fdata.cFileName);
84-
if ((STRLEN)(tmpbuf + sizeof(tmpbuf) - tmpstart) > len) {
84+
if (len < (STRLEN)(tmpbuf - tmpstart + sizeof(tmpbuf))) {
8585
FN_STRCPY(tmpstart, fdata.cFileName);
8686
tmpstart += len;
8787
FindClose(fhand);

0 commit comments

Comments
 (0)