aboutsummaryrefslogtreecommitdiffstats
path: root/wsutil
diff options
context:
space:
mode:
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>2011-02-17 03:02:18 +0000
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>2011-02-17 03:02:18 +0000
commit534538e9cdd1c3fbb2a0aa004b09e0ac52fa1800 (patch)
treeea341abc97164325d81c9bbbcbe192270e1c7f4e /wsutil
parent6be2c49d0989fc849470295bc7cc90d3432a9de9 (diff)
Squelch a warning from the MSVC++ static analyzer (it's worried that
GetModuleHandle() could return a null pointer, which is possible, although if it returns one when handed "kernel32.dll", you have bigger problems...). Add some comments. git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@35972 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'wsutil')
-rw-r--r--wsutil/privileges.c34
1 files changed, 29 insertions, 5 deletions
diff --git a/wsutil/privileges.c b/wsutil/privileges.c
index 8dc5177737..7e51101c5d 100644
--- a/wsutil/privileges.c
+++ b/wsutil/privileges.c
@@ -41,11 +41,13 @@
/*
* Called when the program starts, to save whatever credential information
- * we'll need later.
+ * we'll need later, and to do whatever other specialized platform-dependent
+ * initialization we want.
*/
void
init_process_policies(void)
{
+ HMODULE kernel32Handle;
typedef BOOL (*SetProcessDEPPolicyHandler)(DWORD);
SetProcessDEPPolicyHandler PSetProcessDEPPolicy;
@@ -53,8 +55,24 @@ init_process_policies(void)
#define PROCESS_DEP_ENABLE 1
#endif
- if (PSetProcessDEPPolicy = (SetProcessDEPPolicyHandler) GetProcAddress(GetModuleHandle(_T("kernel32.dll")), "SetProcessDEPPolicy")) {
- PSetProcessDEPPolicy(PROCESS_DEP_ENABLE);
+ /*
+ * If we have SetProcessDEPPolicy(), turn "data execution
+ * prevention" on - i.e., if the MMU lets you set execute
+ * permission on a per-page basis, turn execute permission
+ * off on most data pages. PSetProcessDEPPolicy() fails on
+ * 64-bit Windows (it's *always* on there), but if it fails,
+ * we don't care (we did our best), so we don't check for
+ * errors.
+ *
+ * XXX - if the GetModuleHandle() call fails, should we report
+ * an error? That "shouldn't happen" - it's the equivalent
+ * of libc.{so,sl,a} or libSystem.dylib being missing on UN*X.
+ */
+ kernel32Handle = GetModuleHandle(_T("kernel32.dll"));
+ if (kernel32Handle != NULL) {
+ if (PSetProcessDEPPolicy = (SetProcessDEPPolicyHandler) GetProcAddress(kernel32Handle, "SetProcessDEPPolicy")) {
+ PSetProcessDEPPolicy(PROCESS_DEP_ENABLE);
+ }
}
npf_sys_is_running();
@@ -164,8 +182,14 @@ static gboolean init_process_policies_called = FALSE;
/*
* Called when the program starts, to save whatever credential information
- * we'll need later.
- * That'd be the real and effective UID and GID on UNIX.
+ * we'll need later, and to do whatever other specialized platform-dependent
+ * initialization we want.
+ *
+ * The credential information we'll need later on UNIX is the real and
+ * effective UID and GID.
+ *
+ * XXX - do any UN*Xes have opt-in "no execute on data pages by default"
+ * permission? This would be the place to request it.
*/
void
init_process_policies(void)