From db905292a144241f781c451d1e72f8992abbf97a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
Date: Wed, 2 Mar 2016 04:24:35 +0100
Subject: kernel32: Check for invalid filename pointers in CreateFileA in Win
 9X mode.

The demo version of Test Drive 5 loops through a list of filenames and opens
them using CreateFileA. The stop condition is not correct and the game reads
past the end of the array and therefore passes several invalid pointers to
the CreateFileA API. Windows 98 catches those invalid pointers and the game
can load sucessfully. This commit adds the same behavior when setting the
Windows version to 9X.
---
 dlls/kernel32/file.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/dlls/kernel32/file.c b/dlls/kernel32/file.c
index b6dba6a..750a8ac 100644
--- a/dlls/kernel32/file.c
+++ b/dlls/kernel32/file.c
@@ -1629,6 +1629,7 @@ HANDLE WINAPI CreateFileA( LPCSTR filename, DWORD access, DWORD sharing,
 {
     WCHAR *nameW;
 
+    if ((GetVersion() & 0x80000000) && IsBadStringPtrA(filename, -1)) return INVALID_HANDLE_VALUE;
     if (!(nameW = FILE_name_AtoW( filename, FALSE ))) return INVALID_HANDLE_VALUE;
     return CreateFileW( nameW, access, sharing, sa, creation, attributes, template );
 }
-- 
2.7.1

