Skip to content

Commit 7def882

Browse files
committed
Win32 0.52_02
Fix various -Wunused warnings, added () usage croaks. Fixed a -Warray-bounds buffer overflow in LONGPATH, and two -Wmaybe-uninitialized.
1 parent 62bd746 commit 7def882

File tree

4 files changed

+71
-18
lines changed

4 files changed

+71
-18
lines changed

Changes

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
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+
39
0.52_01 [2017-11-30]
410
- add missing const
511

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_01';
11+
$VERSION = '0.52_02';
1212
$XS_VERSION = $VERSION;
1313
$VERSION = eval $VERSION;
1414

Win32.xs

Lines changed: 63 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <wctype.h>
33
#include <windows.h>
44
#include <shlobj.h>
5+
#include <wchar.h>
56

67
#define PERL_NO_GET_CONTEXT
78
#include "EXTERN.h"
@@ -114,7 +115,7 @@ typedef void (WINAPI *PFNGetNativeSystemInfo)(LPSYSTEM_INFO lpSystemInfo);
114115
* WORD type has been replaced by unsigned short because
115116
* WORD is already used by Perl itself.
116117
*/
117-
struct {
118+
struct g_osver_t {
118119
DWORD dwOSVersionInfoSize;
119120
DWORD dwMajorVersion;
120121
DWORD dwMinorVersion;
@@ -126,7 +127,7 @@ struct {
126127
unsigned short wSuiteMask;
127128
BYTE wProductType;
128129
BYTE wReserved;
129-
} g_osver = {0, 0, 0, 0, 0, "", 0, 0, 0, 0, 0};
130+
} g_osver = {0, 0, 0, 0, 0, "", 0, 0, 0, 0, 0};
130131
BOOL g_osver_ex = TRUE;
131132

132133
#define ONE_K_BUFSIZE 1024
@@ -377,6 +378,7 @@ get_childenv(void)
377378
void
378379
free_childenv(void *d)
379380
{
381+
PERL_UNUSED_ARG(d);
380382
}
381383

382384
# define PerlDir_mapA(dir) (dir)
@@ -388,7 +390,7 @@ XS(w32_ExpandEnvironmentStrings)
388390
dXSARGS;
389391

390392
if (items != 1)
391-
croak("usage: Win32::ExpandEnvironmentStrings($String);\n");
393+
croak("usage: Win32::ExpandEnvironmentStrings($String)");
392394

393395
if (IsWin2000()) {
394396
WCHAR value[31*1024];
@@ -536,7 +538,7 @@ XS(w32_LookupAccountName)
536538

537539
if (items != 5)
538540
croak("usage: Win32::LookupAccountName($system, $account, $domain, "
539-
"$sid, $sidtype);\n");
541+
"$sid, $sidtype)");
540542

541543
SIDLen = sizeof(SID);
542544
DomLen = sizeof(Domain);
@@ -570,7 +572,7 @@ XS(w32_LookupAccountSID)
570572
BOOL bResult;
571573

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

575577
sid = SvPV_nolen(ST(1));
576578
if (IsValidSid(sid)) {
@@ -601,7 +603,7 @@ XS(w32_InitiateSystemShutdown)
601603

602604
if (items != 5)
603605
croak("usage: Win32::InitiateSystemShutdown($machineName, $message, "
604-
"$timeOut, $forceClose, $reboot);\n");
606+
"$timeOut, $forceClose, $reboot)");
605607

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

@@ -642,7 +644,7 @@ XS(w32_AbortSystemShutdown)
642644
char *machineName;
643645

644646
if (items != 1)
645-
croak("usage: Win32::AbortSystemShutdown($machineName);\n");
647+
croak("usage: Win32::AbortSystemShutdown($machineName)");
646648

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

@@ -680,7 +682,7 @@ XS(w32_MsgBox)
680682
I32 result;
681683

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

685687
if (items > 1)
686688
flags = (DWORD)SvIV(ST(1));
@@ -787,6 +789,8 @@ XS(w32_UnregisterServer)
787789
XS(w32_GetArchName)
788790
{
789791
dXSARGS;
792+
if (items)
793+
Perl_croak(aTHX_ "usage: Win32::GetArchName()");
790794
XSRETURN_PV(getenv("PROCESSOR_ARCHITECTURE"));
791795
}
792796

@@ -796,6 +800,8 @@ XS(w32_GetChipName)
796800
SYSTEM_INFO sysinfo;
797801
HMODULE module;
798802
PFNGetNativeSystemInfo pfnGetNativeSystemInfo;
803+
if (items)
804+
Perl_croak(aTHX_ "usage: Win32::GetChipName()");
799805

800806
Zero(&sysinfo,1,SYSTEM_INFO);
801807
module = GetModuleHandle("kernel32.dll");
@@ -814,8 +820,11 @@ XS(w32_GuidGen)
814820
dXSARGS;
815821
GUID guid;
816822
char szGUID[50] = {'\0'};
817-
HRESULT hr = CoCreateGuid(&guid);
823+
HRESULT hr;
824+
if (items)
825+
Perl_croak(aTHX_ "usage: Win32::GuidGen()");
818826

827+
hr = CoCreateGuid(&guid);
819828
if (SUCCEEDED(hr)) {
820829
LPOLESTR pStr = NULL;
821830
#ifdef __cplusplus
@@ -997,7 +1006,7 @@ XS(w32_GetFileVersion)
9971006
char *data;
9981007

9991008
if (items != 1)
1000-
croak("usage: Win32::GetFileVersion($filename)\n");
1009+
croak("usage: Win32::GetFileVersion($filename)");
10011010

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

10561067
XS(w32_GetCwd)
10571068
{
10581069
dXSARGS;
1070+
char* ptr;
1071+
if (items)
1072+
Perl_croak(aTHX_ "usage: Win32::GetCwd()");
1073+
10591074
/* Make the host for current directory */
1060-
char* ptr = PerlEnv_get_childdir();
1075+
ptr = PerlEnv_get_childdir();
10611076
/*
10621077
* If ptr != Nullch
10631078
* then it worked, set PV valid,
@@ -1108,6 +1123,8 @@ XS(w32_GetNextAvailDrive)
11081123
char ix = 'C';
11091124
char root[] = "_:\\";
11101125

1126+
if (items)
1127+
Perl_croak(aTHX_ "usage: Win32::GetNextAvailDrive()");
11111128
EXTEND(SP,1);
11121129
while (ix <= 'Z') {
11131130
root[0] = ix++;
@@ -1122,6 +1139,8 @@ XS(w32_GetNextAvailDrive)
11221139
XS(w32_GetLastError)
11231140
{
11241141
dXSARGS;
1142+
if (items)
1143+
Perl_croak(aTHX_ "usage: Win32::GetLastError()");
11251144
EXTEND(SP,1);
11261145
XSRETURN_IV(GetLastError());
11271146
}
@@ -1138,6 +1157,8 @@ XS(w32_SetLastError)
11381157
XS(w32_LoginName)
11391158
{
11401159
dXSARGS;
1160+
if (items)
1161+
Perl_croak(aTHX_ "usage: Win32::LoginName()");
11411162
EXTEND(SP,1);
11421163
if (IsWin2000()) {
11431164
WCHAR name[128];
@@ -1164,6 +1185,8 @@ XS(w32_NodeName)
11641185
dXSARGS;
11651186
char name[MAX_COMPUTERNAME_LENGTH+1];
11661187
DWORD size = sizeof(name);
1188+
if (items)
1189+
Perl_croak(aTHX_ "usage: Win32::NodeName()");
11671190
EXTEND(SP,1);
11681191
if (GetComputerName(name,&size)) {
11691192
/* size does NOT include NULL :-( */
@@ -1178,9 +1201,11 @@ XS(w32_DomainName)
11781201
{
11791202
dXSARGS;
11801203
HMODULE module = LoadLibrary("netapi32.dll");
1181-
PFNNetApiBufferFree pfnNetApiBufferFree;
1182-
PFNNetWkstaGetInfo pfnNetWkstaGetInfo;
1204+
PFNNetApiBufferFree pfnNetApiBufferFree = NULL;
1205+
PFNNetWkstaGetInfo pfnNetWkstaGetInfo = NULL;
11831206

1207+
if (items)
1208+
Perl_croak(aTHX_ "usage: Win32::DomainName()");
11841209
if (module) {
11851210
GETPROC(NetApiBufferFree);
11861211
GETPROC(NetWkstaGetInfo);
@@ -1242,8 +1267,10 @@ XS(w32_FsType)
12421267
dXSARGS;
12431268
char fsname[256];
12441269
DWORD flags, filecomplen;
1270+
if (items)
1271+
Perl_croak(aTHX_ "usage: Win32::FsType()");
12451272
if (GetVolumeInformation(NULL, NULL, 0, NULL, &filecomplen,
1246-
&flags, fsname, sizeof(fsname))) {
1273+
&flags, fsname, sizeof(fsname))) {
12471274
if (GIMME_V == G_ARRAY) {
12481275
XPUSHs(sv_2mortal(newSVpvn(fsname,strlen(fsname))));
12491276
XPUSHs(sv_2mortal(newSViv(flags)));
@@ -1260,6 +1287,8 @@ XS(w32_FsType)
12601287
XS(w32_GetOSVersion)
12611288
{
12621289
dXSARGS;
1290+
if (items)
1291+
Perl_croak(aTHX_ "usage: Win32::GetOSVersion()");
12631292

12641293
if (GIMME_V == G_SCALAR) {
12651294
XSRETURN_IV(g_osver.dwPlatformId);
@@ -1282,13 +1311,17 @@ XS(w32_GetOSVersion)
12821311
XS(w32_IsWinNT)
12831312
{
12841313
dXSARGS;
1314+
if (items)
1315+
Perl_croak(aTHX_ "usage: Win32::IsWinNT()");
12851316
EXTEND(SP,1);
12861317
XSRETURN_IV(IsWinNT());
12871318
}
12881319

12891320
XS(w32_IsWin95)
12901321
{
12911322
dXSARGS;
1323+
if (items)
1324+
Perl_croak(aTHX_ "usage: Win32::IsWin95()");
12921325
EXTEND(SP,1);
12931326
XSRETURN_IV(IsWin95());
12941327
}
@@ -1364,6 +1397,8 @@ XS(w32_GetTickCount)
13641397
{
13651398
dXSARGS;
13661399
DWORD msec = GetTickCount();
1400+
if (items)
1401+
Perl_croak(aTHX_ "usage: Win32::GetTickCount()");
13671402
EXTEND(SP,1);
13681403
if ((IV)msec > 0)
13691404
XSRETURN_IV(msec);
@@ -1525,7 +1560,7 @@ XS(w32_GetLongPathName)
15251560
WCHAR wide_path[MAX_PATH+1];
15261561
WCHAR *long_path;
15271562

1528-
if (wcslen(wstr) < countof(wide_path)) {
1563+
if (wcslen(wstr) < (size_t)countof(wide_path)) {
15291564
wcscpy(wide_path, wstr);
15301565
long_path = my_longpathW(wide_path);
15311566
if (long_path) {
@@ -1619,13 +1654,17 @@ XS(w32_OutputDebugString)
16191654
XS(w32_GetCurrentProcessId)
16201655
{
16211656
dXSARGS;
1657+
if (items)
1658+
Perl_croak(aTHX_ "usage: Win32::GetCurrentProcessId()");
16221659
EXTEND(SP,1);
16231660
XSRETURN_IV(GetCurrentProcessId());
16241661
}
16251662

16261663
XS(w32_GetCurrentThreadId)
16271664
{
16281665
dXSARGS;
1666+
if (items)
1667+
Perl_croak(aTHX_ "usage: Win32::GetCurrentThreadId()");
16291668
EXTEND(SP,1);
16301669
XSRETURN_IV(GetCurrentThreadId());
16311670
}
@@ -1713,27 +1752,35 @@ XS(w32_GetProductInfo)
17131752
XS(w32_GetACP)
17141753
{
17151754
dXSARGS;
1755+
if (items)
1756+
Perl_croak(aTHX_ "usage: Win32::GetACP()");
17161757
EXTEND(SP,1);
17171758
XSRETURN_IV(GetACP());
17181759
}
17191760

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

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

17341779
XS(w32_GetOEMCP)
17351780
{
17361781
dXSARGS;
1782+
if (items)
1783+
Perl_croak(aTHX_ "usage: Win32::GetOEMCP()");
17371784
EXTEND(SP,1);
17381785
XSRETURN_IV(GetOEMCP());
17391786
}

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)