krnl386.exe: Fix VxD filename format checks in __wine_vxd_open().

__wine_vxd_open() has several bugs. If filenameW doesn't end in
".vxd", it is wrongly
allowed to be over 8 characters long. If it does end in ".vxd", then a
maximum length
filename, eg. "12345678.vxd", always gets misdetected as being too long, as:
"lstrlenW( filenameW ) >= ARRAY_SIZE(name) - 4"
becomes 12 >= 12.

Rather do the checks for maximum filename length when we detect the
filename format.

Signed-off-by: Damjan Jovanovic <damjan.jov@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Damjan Jovanovic 2022-02-23 05:16:13 +02:00 committed by Alexandre Julliard
parent bf8c5afef1
commit fc4726c225
1 changed files with 17 additions and 12 deletions

View File

@ -136,29 +136,34 @@ done:
/* load a VxD and return a file handle to it */
HANDLE __wine_vxd_open( LPCWSTR filenameW, DWORD access, SECURITY_ATTRIBUTES *sa )
{
static const WCHAR dotVxDW[] = {'.','v','x','d',0};
int i;
HANDLE handle;
HMODULE module;
WCHAR *p, name[16];
WCHAR *p, name[13];
/* normalize the filename */
if (lstrlenW( filenameW ) >= ARRAY_SIZE(name) - 4 ||
wcschr( filenameW, '/' ) || wcschr( filenameW, '\\' ))
if (wcschr( filenameW, '/' ) || wcschr( filenameW, '\\' ))
{
SetLastError( ERROR_FILE_NOT_FOUND );
return 0;
}
p = wcschr( filenameW, '.' );
if (!p && lstrlenW( filenameW ) <= 8)
{
wcscpy( name, filenameW );
wcscat( name, L".vxd" );
}
else if (p && !wcsicmp( p, L".vxd" ) && lstrlenW( filenameW ) <= 12) /* existing extension has to be .vxd */
{
wcscpy( name, filenameW );
}
else
{
SetLastError( ERROR_FILE_NOT_FOUND );
return 0;
}
lstrcpyW( name, filenameW );
wcslwr( name );
p = wcschr( name, '.' );
if (!p) lstrcatW( name, dotVxDW );
else if (wcsicmp( p, dotVxDW )) /* existing extension has to be .vxd */
{
SetLastError( ERROR_FILE_NOT_FOUND );
return 0;
}
/* try to load the module first */