Partial fix for bug 5133. On Windows, call SetDllDirectory at startup if
authorgerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 24 Aug 2010 23:39:29 +0000 (23:39 +0000)
committergerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 24 Aug 2010 23:39:29 +0000 (23:39 +0000)
it's present in Wireshark and dumpcap. This takes care of the airpcap.dll
PoC but we need to load wpcap.dll from a full path. We might want to
call SetDllDirectory from our other executables as well.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@33916 f5534014-38df-0310-8fa8-9805f1628bb7

dumpcap.c
gtk/main.c

index a62b726018bb6e61d501639a10247369b05bc6d7..312434950c412e79ec09950a60364a1e47976312 100644 (file)
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -3273,6 +3273,8 @@ main(int argc, char *argv[])
 
 #ifdef _WIN32
   WSADATA              wsaData;
+  typedef BOOL (*SetDllDirectoryHandler)(LPCTSTR);
+  SetDllDirectoryHandler PSetDllDirectory;
 #else
   struct sigaction action, oldaction;
 #endif
@@ -3294,6 +3296,11 @@ main(int argc, char *argv[])
   struct utsname       osinfo;
 #endif
 
+  if (PSetDllDirectory = (SetDllDirectoryHandler) GetProcAddress(GetModuleHandle(_T("kernel32.dll")), "SetDllDirectoryW")) {
+    PSetDllDirectory(_T(""));
+    /* XXX - Exit on failure? */
+  }
+
 #ifdef HAVE_PCAP_REMOTE
 #define OPTSTRING_A "A:"
 #define OPTSTRING_r "r"
index ffb18039fb2716215939f34868d704c4a1cf760f..74631d460a8e92fbc485291ddde75e05cfc9dec4 100644 (file)
@@ -222,6 +222,7 @@ guint  tap_update_timer_id;
 static gboolean has_console;   /* TRUE if app has console */
 static void destroy_console(void);
 static gboolean stdin_capture = FALSE; /* Don't grab stdin & stdout if TRUE */
+static gboolean dll_set = FALSE; /* Did we sucessfully trim our DLL path? */
 #endif
 static void console_log_handler(const char *log_domain,
     GLogLevelFlags log_level, const char *message, gpointer user_data);
@@ -2108,6 +2109,11 @@ main(int argc, char *argv[])
       argv[i] = g_strdup(utf_16to8(wc_argv[i]));
     }
   } /* XXX else bail because something is horribly, horribly wrong? */
+
+  if (!dll_set) {
+    simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "SetDllDirectory failed (%d)!\n", GetLastError());
+    /* XXX - Exit? */
+  }
 #endif /* _WIN32 */
 
   /*
@@ -2701,8 +2707,6 @@ main(int argc, char *argv[])
     argv++;
   }
 
-
-
   if (argc != 0) {
     /*
      * Extra command line arguments were specified; complain.
@@ -3094,6 +3098,12 @@ WinMain (struct HINSTANCE__ *hInstance,
         int                 nCmdShow)
 {
   INITCOMMONCONTROLSEX comm_ctrl;
+  typedef BOOL (*SetDllDirectoryHandler)(LPCTSTR);
+  SetDllDirectoryHandler PSetDllDirectory;
+
+  if (PSetDllDirectory = (SetDllDirectoryHandler) GetProcAddress(GetModuleHandle(_T("kernel32.dll")), "SetDllDirectoryW")) {
+    dll_set = PSetDllDirectory(_T(""));
+  }
 
   /* Initialize our controls. Required for native Windows file dialogs. */
   memset (&comm_ctrl, 0, sizeof(comm_ctrl));