Skip to content

Commit fec15a1

Browse files
authored
Merge pull request #13 from rurban/master
minor fixes to 0.52_02
2 parents a05f3d5 + 7def882 commit fec15a1

File tree

4 files changed

+75
-19
lines changed

4 files changed

+75
-19
lines changed

Changes

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
Revision history for the Perl extension Win32.
22

3+
0.52_02 [2018-11-02]
4+
- added () usage croaks.
5+
- Fixed a -Warray-bounds buffer overflow in LONGPATH,
6+
- Fix various -Wunused warnings
7+
and two -Wmaybe-uninitialized.
8+
9+
0.52_01 [2017-11-30]
10+
- add missing const
11+
312
0.52 [2015-08-19]
413
- minimal Windows 10 support (thanks to Joel Maslak) [PR/8]
514
- refactor Windows 10 support to include ProductInfo flags

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.52_02';
1212
$XS_VERSION = $VERSION;
1313
$VERSION = eval $VERSION;
1414

Win32.xs

Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <wctype.h>
44
#include <windows.h>
55
#include <shlobj.h>
6+
#include <wchar.h>
67

78
#define PERL_NO_GET_CONTEXT
89
#include "EXTERN.h"
@@ -115,7 +116,7 @@ typedef void (WINAPI *PFNGetNativeSystemInfo)(LPSYSTEM_INFO lpSystemInfo);
115116
* WORD type has been replaced by unsigned short because
116117
* WORD is already used by Perl itself.
117118
*/
118-
struct {
119+
struct g_osver_t {
119120
DWORD dwOSVersionInfoSize;
120121
DWORD dwMajorVersion;
121122
DWORD dwMinorVersion;
@@ -127,7 +128,7 @@ struct {
127128
unsigned short wSuiteMask;
128129
BYTE wProductType;
129130
BYTE wReserved;
130-
} 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};
131132
BOOL g_osver_ex = TRUE;
132133

133134
#define ONE_K_BUFSIZE 1024
@@ -378,6 +379,7 @@ get_childenv(void)
378379
void
379380
free_childenv(void *d)
380381
{
382+
PERL_UNUSED_ARG(d);
381383
}
382384

383385
# define PerlDir_mapA(dir) (dir)
@@ -389,7 +391,7 @@ XS(w32_ExpandEnvironmentStrings)
389391
dXSARGS;
390392

391393
if (items != 1)
392-
croak("usage: Win32::ExpandEnvironmentStrings($String);\n");
394+
croak("usage: Win32::ExpandEnvironmentStrings($String)");
393395

394396
if (IsWin2000()) {
395397
WCHAR value[31*1024];
@@ -537,7 +539,7 @@ XS(w32_LookupAccountName)
537539

538540
if (items != 5)
539541
croak("usage: Win32::LookupAccountName($system, $account, $domain, "
540-
"$sid, $sidtype);\n");
542+
"$sid, $sidtype)");
541543

542544
SIDLen = sizeof(SID);
543545
DomLen = sizeof(Domain);
@@ -571,7 +573,7 @@ XS(w32_LookupAccountSID)
571573
BOOL bResult;
572574

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

576578
sid = SvPV_nolen(ST(1));
577579
if (IsValidSid(sid)) {
@@ -602,7 +604,7 @@ XS(w32_InitiateSystemShutdown)
602604

603605
if (items != 5)
604606
croak("usage: Win32::InitiateSystemShutdown($machineName, $message, "
605-
"$timeOut, $forceClose, $reboot);\n");
607+
"$timeOut, $forceClose, $reboot)");
606608

607609
machineName = SvPV_nolen(ST(0));
608610

@@ -643,7 +645,7 @@ XS(w32_AbortSystemShutdown)
643645
char *machineName;
644646

645647
if (items != 1)
646-
croak("usage: Win32::AbortSystemShutdown($machineName);\n");
648+
croak("usage: Win32::AbortSystemShutdown($machineName)");
647649

648650
machineName = SvPV_nolen(ST(0));
649651

@@ -681,7 +683,7 @@ XS(w32_MsgBox)
681683
I32 result;
682684

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

686688
if (items > 1)
687689
flags = (DWORD)SvIV(ST(1));
@@ -788,6 +790,8 @@ XS(w32_UnregisterServer)
788790
XS(w32_GetArchName)
789791
{
790792
dXSARGS;
793+
if (items)
794+
Perl_croak(aTHX_ "usage: Win32::GetArchName()");
791795
XSRETURN_PV(getenv("PROCESSOR_ARCHITECTURE"));
792796
}
793797

@@ -797,6 +801,8 @@ XS(w32_GetChipName)
797801
SYSTEM_INFO sysinfo;
798802
HMODULE module;
799803
PFNGetNativeSystemInfo pfnGetNativeSystemInfo;
804+
if (items)
805+
Perl_croak(aTHX_ "usage: Win32::GetChipName()");
800806

801807
Zero(&sysinfo,1,SYSTEM_INFO);
802808
module = GetModuleHandle("kernel32.dll");
@@ -815,8 +821,11 @@ XS(w32_GuidGen)
815821
dXSARGS;
816822
GUID guid;
817823
char szGUID[50] = {'\0'};
818-
HRESULT hr = CoCreateGuid(&guid);
824+
HRESULT hr;
825+
if (items)
826+
Perl_croak(aTHX_ "usage: Win32::GuidGen()");
819827

828+
hr = CoCreateGuid(&guid);
820829
if (SUCCEEDED(hr)) {
821830
LPOLESTR pStr = NULL;
822831
#ifdef __cplusplus
@@ -998,7 +1007,7 @@ XS(w32_GetFileVersion)
9981007
char *data;
9991008

10001009
if (items != 1)
1001-
croak("usage: Win32::GetFileVersion($filename)\n");
1010+
croak("usage: Win32::GetFileVersion($filename)");
10021011

10031012
filename = SvPV_nolen(ST(0));
10041013
size = GetFileVersionInfoSize(filename, &handle);
@@ -1049,16 +1058,22 @@ XS(w32_SetChildShowWindow)
10491058
* inside the thread_intern structure, the MSWin32 implementation
10501059
* lives in win32/win32.c in the core Perl distribution.
10511060
*/
1052-
dXSARGS;
1061+
dSP;
1062+
I32 ax = POPMARK;
1063+
EXTEND(SP,1);
10531064
XSRETURN_UNDEF;
10541065
}
10551066
#endif
10561067

10571068
XS(w32_GetCwd)
10581069
{
10591070
dXSARGS;
1071+
char* ptr;
1072+
if (items)
1073+
Perl_croak(aTHX_ "usage: Win32::GetCwd()");
1074+
10601075
/* Make the host for current directory */
1061-
char* ptr = PerlEnv_get_childdir();
1076+
ptr = PerlEnv_get_childdir();
10621077
/*
10631078
* If ptr != Nullch
10641079
* then it worked, set PV valid,
@@ -1109,6 +1124,8 @@ XS(w32_GetNextAvailDrive)
11091124
char ix = 'C';
11101125
char root[] = "_:\\";
11111126

1127+
if (items)
1128+
Perl_croak(aTHX_ "usage: Win32::GetNextAvailDrive()");
11121129
EXTEND(SP,1);
11131130
while (ix <= 'Z') {
11141131
root[0] = ix++;
@@ -1123,6 +1140,8 @@ XS(w32_GetNextAvailDrive)
11231140
XS(w32_GetLastError)
11241141
{
11251142
dXSARGS;
1143+
if (items)
1144+
Perl_croak(aTHX_ "usage: Win32::GetLastError()");
11261145
EXTEND(SP,1);
11271146
XSRETURN_IV(GetLastError());
11281147
}
@@ -1139,6 +1158,8 @@ XS(w32_SetLastError)
11391158
XS(w32_LoginName)
11401159
{
11411160
dXSARGS;
1161+
if (items)
1162+
Perl_croak(aTHX_ "usage: Win32::LoginName()");
11421163
EXTEND(SP,1);
11431164
if (IsWin2000()) {
11441165
WCHAR name[128];
@@ -1165,6 +1186,8 @@ XS(w32_NodeName)
11651186
dXSARGS;
11661187
char name[MAX_COMPUTERNAME_LENGTH+1];
11671188
DWORD size = sizeof(name);
1189+
if (items)
1190+
Perl_croak(aTHX_ "usage: Win32::NodeName()");
11681191
EXTEND(SP,1);
11691192
if (GetComputerName(name,&size)) {
11701193
/* size does NOT include NULL :-( */
@@ -1179,9 +1202,11 @@ XS(w32_DomainName)
11791202
{
11801203
dXSARGS;
11811204
HMODULE module = LoadLibrary("netapi32.dll");
1182-
PFNNetApiBufferFree pfnNetApiBufferFree;
1183-
PFNNetWkstaGetInfo pfnNetWkstaGetInfo;
1205+
PFNNetApiBufferFree pfnNetApiBufferFree = NULL;
1206+
PFNNetWkstaGetInfo pfnNetWkstaGetInfo = NULL;
11841207

1208+
if (items)
1209+
Perl_croak(aTHX_ "usage: Win32::DomainName()");
11851210
if (module) {
11861211
GETPROC(NetApiBufferFree);
11871212
GETPROC(NetWkstaGetInfo);
@@ -1243,8 +1268,10 @@ XS(w32_FsType)
12431268
dXSARGS;
12441269
char fsname[256];
12451270
DWORD flags, filecomplen;
1271+
if (items)
1272+
Perl_croak(aTHX_ "usage: Win32::FsType()");
12461273
if (GetVolumeInformation(NULL, NULL, 0, NULL, &filecomplen,
1247-
&flags, fsname, sizeof(fsname))) {
1274+
&flags, fsname, sizeof(fsname))) {
12481275
if (GIMME_V == G_ARRAY) {
12491276
XPUSHs(sv_2mortal(newSVpvn(fsname,strlen(fsname))));
12501277
XPUSHs(sv_2mortal(newSViv(flags)));
@@ -1261,6 +1288,8 @@ XS(w32_FsType)
12611288
XS(w32_GetOSVersion)
12621289
{
12631290
dXSARGS;
1291+
if (items)
1292+
Perl_croak(aTHX_ "usage: Win32::GetOSVersion()");
12641293

12651294
if (GIMME_V == G_SCALAR) {
12661295
XSRETURN_IV(g_osver.dwPlatformId);
@@ -1283,13 +1312,17 @@ XS(w32_GetOSVersion)
12831312
XS(w32_IsWinNT)
12841313
{
12851314
dXSARGS;
1315+
if (items)
1316+
Perl_croak(aTHX_ "usage: Win32::IsWinNT()");
12861317
EXTEND(SP,1);
12871318
XSRETURN_IV(IsWinNT());
12881319
}
12891320

12901321
XS(w32_IsWin95)
12911322
{
12921323
dXSARGS;
1324+
if (items)
1325+
Perl_croak(aTHX_ "usage: Win32::IsWin95()");
12931326
EXTEND(SP,1);
12941327
XSRETURN_IV(IsWin95());
12951328
}
@@ -1365,6 +1398,8 @@ XS(w32_GetTickCount)
13651398
{
13661399
dXSARGS;
13671400
DWORD msec = GetTickCount();
1401+
if (items)
1402+
Perl_croak(aTHX_ "usage: Win32::GetTickCount()");
13681403
EXTEND(SP,1);
13691404
if ((IV)msec > 0)
13701405
XSRETURN_IV(msec);
@@ -1526,7 +1561,7 @@ XS(w32_GetLongPathName)
15261561
WCHAR wide_path[MAX_PATH+1];
15271562
WCHAR *long_path;
15281563

1529-
if (wcslen(wstr) < countof(wide_path)) {
1564+
if (wcslen(wstr) < (size_t)countof(wide_path)) {
15301565
wcscpy(wide_path, wstr);
15311566
long_path = my_longpathW(wide_path);
15321567
if (long_path) {
@@ -1620,13 +1655,17 @@ XS(w32_OutputDebugString)
16201655
XS(w32_GetCurrentProcessId)
16211656
{
16221657
dXSARGS;
1658+
if (items)
1659+
Perl_croak(aTHX_ "usage: Win32::GetCurrentProcessId()");
16231660
EXTEND(SP,1);
16241661
XSRETURN_IV(GetCurrentProcessId());
16251662
}
16261663

16271664
XS(w32_GetCurrentThreadId)
16281665
{
16291666
dXSARGS;
1667+
if (items)
1668+
Perl_croak(aTHX_ "usage: Win32::GetCurrentThreadId()");
16301669
EXTEND(SP,1);
16311670
XSRETURN_IV(GetCurrentThreadId());
16321671
}
@@ -1714,27 +1753,35 @@ XS(w32_GetProductInfo)
17141753
XS(w32_GetACP)
17151754
{
17161755
dXSARGS;
1756+
if (items)
1757+
Perl_croak(aTHX_ "usage: Win32::GetACP()");
17171758
EXTEND(SP,1);
17181759
XSRETURN_IV(GetACP());
17191760
}
17201761

17211762
XS(w32_GetConsoleCP)
17221763
{
17231764
dXSARGS;
1765+
if (items)
1766+
Perl_croak(aTHX_ "usage: Win32::GetConsoleCP()");
17241767
EXTEND(SP,1);
17251768
XSRETURN_IV(GetConsoleCP());
17261769
}
17271770

17281771
XS(w32_GetConsoleOutputCP)
17291772
{
17301773
dXSARGS;
1774+
if (items)
1775+
Perl_croak(aTHX_ "usage: Win32::GetConsoleOutputCP()");
17311776
EXTEND(SP,1);
17321777
XSRETURN_IV(GetConsoleOutputCP());
17331778
}
17341779

17351780
XS(w32_GetOEMCP)
17361781
{
17371782
dXSARGS;
1783+
if (items)
1784+
Perl_croak(aTHX_ "usage: Win32::GetOEMCP()");
17381785
EXTEND(SP,1);
17391786
XSRETURN_IV(GetOEMCP());
17401787
}
@@ -1765,7 +1812,7 @@ PROTOTYPES: DISABLE
17651812

17661813
BOOT:
17671814
{
1768-
char *file = __FILE__;
1815+
const char *file = __FILE__;
17691816

17701817
if (g_osver.dwOSVersionInfoSize == 0) {
17711818
g_osver.dwOSVersionInfoSize = sizeof(g_osver);

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 ((STRLEN)(len < tmpbuf - tmpstart + sizeof(tmpbuf))) {
8585
FN_STRCPY(tmpstart, fdata.cFileName);
8686
tmpstart += len;
8787
FindClose(fhand);

0 commit comments

Comments
 (0)