[openssl-dev] [openssl.org #3820] [PATCH] Remove an unnecessary call to USER32!GetDesktopWindow

Gunnar Kudrjavets via RT rt at openssl.org
Sat Apr 25 09:13:04 UTC 2015


Hello,

Summary: currently function LIBEAY32!OPENSSL_isservice() calls USER32!GetDesktopWindow() to determine if the code is running as a service or not. That function call is not necessary. Attached patch has the details.

Additional data:

1) Operating systems affected: all version of Windows.

2) OpenSSL versions affected: all versions running on Windows, starting Apr 7 2005.

Thank you,
Gunnar Kudrjavets


-------------- next part --------------
>From 7693250e03ea284c2fb3a565cd3cbceeb2512943 Mon Sep 17 00:00:00 2001
From: Gunnar Kudrjavets <gunnarku at microsoft.com>
Date: Thu, 23 Apr 2015 13:22:49 -0700
Subject: [PATCH] Remove an unnecessary call to USER32!GetDesktopWindow

Currently function LIBEAY32!OPENSSL_isservice() calls GetDesktopWindow()
to determine if the code is running as a service or not. There are a couple
of issues with that:

1) That function call is not necessary and given that its result is ignored
then it can be removed from the code.

2) It introduces an unnecessary dependency on whatever binary happens to host
GetDesktopWindow() in some API Set on a particular version of Windows.

Testing performed:

1) Clean compilation for debug-VC-WIN32 and VC-WIN32.

2) Good test results (nmake -f ms\ntdll.mak test) for debug-VC-WIN32 and
VC-WIN32.

3) Stepped through relevant changes using WinDBG in cases when code was
both running as part of the service and not. Verified that the existing
behavior is maintained. The following OS-s were tested: Windows 8.1 Enterprise,
Windows Server 2012 R2 Datacenter, and Windows XP Version 2002 (SP 3 aka
5.1.2600). The test cases consisted of:

  *) Running a console application and verifying that OPENSSL_isservice()
     returns 0 as expected.

  *) Running a service containing code from OPENSSL_isservice() and verifying
     that the function returns 1 as expected.

The code to call GetDesktopWindow() was originally introduced as part of
9f2027e56d9e82dc89f079ed285d5571cbee5592.
---
 crypto/cryptlib.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/crypto/cryptlib.c b/crypto/cryptlib.c
index ce07b84..be4cdb0 100644
--- a/crypto/cryptlib.c
+++ b/crypto/cryptlib.c
@@ -288,8 +288,6 @@ int OPENSSL_isservice(void)
     if (_OPENSSL_isservice.p != (void *)-1)
         return (*_OPENSSL_isservice.f) ();
 
-    (void)GetDesktopWindow();   /* return value is ignored */
-
     h = GetProcessWindowStation();
     if (h == NULL)
         return -1;
-- 
1.9.5.msysgit.1



More information about the openssl-dev mailing list