From 1c72a62e99240b61d2e37d853461b972fbb12d55 Mon Sep 17 00:00:00 2001
From: ag <ag@MachineLocale.(none)>
Date: Sat, 31 Jan 2009 19:27:31 +0100
Subject: Basic implementation of sanity check

---
 dlls/kernel32/file.c |   36 ++++++++++++++++++++++++++++++++++++
 1 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/dlls/kernel32/file.c b/dlls/kernel32/file.c
index e757205..bd9c177 100644
--- a/dlls/kernel32/file.c
+++ b/dlls/kernel32/file.c
@@ -577,6 +577,30 @@ BOOL WINAPI WriteFile( HANDLE hFile, LPCVOID buffer, DWORD bytesToWrite,
     return TRUE;
 }
 
+/* TODO : ExitWineCleanly and ExitWineCleanlyAndAdvertiseUser must be implement-
+ * ed in another place, centralised (maybe something like MESSAGE)
+ */
+void ExitWineCleanly(void)
+{
+    /* TODO : Cleanly release still alocated resources (only if not already perform-
+     * ed by exit statement)
+     */
+
+    /* Cleany exit wine */
+    exit(EXIT_FAILURE);
+}
+
+void ExitWineCleanlyAndAdvertiseUser(void)
+{
+    /* Output an advertisement message to user */
+    MESSAGE("The application you used present a security defect, so wine cannot run it on safe mode.\n\n");
+    MESSAGE("You can nevertheless run it using wine unsafe mode, but you are discouraged to do so because of the following reasons :\n");
+    MESSAGE("    1 - It will directly expose you to security issues\n");
+    MESSAGE("    2 - It will also indirectly expose other users to security issues (for example you computer can be used in a wide-range attack against a state website)\n");
+
+    /* Cleanly exit wine */
+    ExitWineCleanly();
+}
 
 /***********************************************************************
  *              GetOverlappedResult     (KERNEL32.@)
@@ -601,8 +625,20 @@ BOOL WINAPI GetOverlappedResult(HANDLE hFile, LPOVERLAPPED lpOverlapped,
 {
     NTSTATUS status;
 
+    /* TODO : this variable must be global to wine, and inititialized from
+     * registry.
+     */
+    BOOL safe_mode_on;
+    safe_mode_on = TRUE;
+
     TRACE( "(%p %p %p %x)\n", hFile, lpOverlapped, lpTransferred, bWait );
 
+    /* Sanity checks */
+    if (safe_mode_on && (lpOverlapped == NULL || lpTransferred == NULL))
+    {
+        ExitWineCleanlyAndAdvertiseUser();
+    }
+
     status = lpOverlapped->Internal;
     if (status == STATUS_PENDING)
     {
-- 
1.5.6.5

