You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ma...@apache.org on 2019/05/22 19:50:11 UTC

[commons-daemon] branch master updated: Fix https://issues.apache.org/jira/projects/DAEMON/issues/DAEMON-401

This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-daemon.git


The following commit(s) were added to refs/heads/master by this push:
     new 59d4b50  Fix https://issues.apache.org/jira/projects/DAEMON/issues/DAEMON-401
59d4b50 is described below

commit 59d4b50500d53bd1ad7a04294bc9dd34dd0e7e4c
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed May 22 20:25:57 2019 +0100

    Fix https://issues.apache.org/jira/projects/DAEMON/issues/DAEMON-401
    
    Ensure that environment variables set via prunsrv are visible to native
    libraries that depend on the Universal CRT.
---
 src/changes/changes.xml                   |  4 ++++
 src/native/windows/apps/prunsrv/prunsrv.c | 12 ++++++++++++
 src/native/windows/include/apxwin.h       | 12 ++++++++----
 src/native/windows/src/gui.c              |  2 --
 4 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 865ee63..24bed12 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -87,6 +87,10 @@
         Harden the Windows binaries against DLL hijacking in the directory where
         the binaries are located. 
       </action>
+      <action issue="DAEMON-401" type="fix" dev="markt" due-to="Jonathan Gallimore">
+        Procrun. Ensure that environment variables set via prunsrv are visible
+        to native libraries that depend on the Universal CRT.
+      </action> 
     </release>
     <release version="1.1.0" date="2017-11-15" description="Feature and bug fix release">
       <action issue="DAEMON-368" type="add" dev="ggregory">
diff --git a/src/native/windows/apps/prunsrv/prunsrv.c b/src/native/windows/apps/prunsrv/prunsrv.c
index 8473efb..b125850 100644
--- a/src/native/windows/apps/prunsrv/prunsrv.c
+++ b/src/native/windows/apps/prunsrv/prunsrv.c
@@ -58,6 +58,8 @@ typedef struct APX_STDWRAP {
     FILE   *fpStdErrFile;
 } APX_STDWRAP;
 
+typedef int (__stdcall *WPUTENV) (const wchar_t *env);
+
 /* Use static variables instead of #defines */
 static LPCWSTR  PRSRV_AUTO        = L"auto";
 static LPCWSTR  PRSRV_JAVA        = L"java";
@@ -415,13 +417,23 @@ static void dumpCmdline()
 void apxSetInprocEnvironment()
 {
     LPWSTR p, e;
+    HMODULE hmodUcrt;
+    WPUTENV wputenv_ucrt;
 
     if (!SO_ENVIRONMENT)
         return;    /* Nothing to do */
 
+    hmodUcrt = LoadLibraryExA("ucrtbase.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
+    if (hmodUcrt != NULL) {
+    	wputenv_ucrt =  (WPUTENV) GetProcAddress(hmodUcrt, "_wputenv");
+    }
+
     for (p = SO_ENVIRONMENT; *p; p++) {
         e = apxExpandStrW(gPool, p);
         _wputenv(e);
+        if (wputenv_ucrt != NULL) {
+        	wputenv_ucrt(e);
+        }
         apxFree(e);
         while (*p)
             p++;
diff --git a/src/native/windows/include/apxwin.h b/src/native/windows/include/apxwin.h
index 8a9f842..ca7552a 100644
--- a/src/native/windows/include/apxwin.h
+++ b/src/native/windows/include/apxwin.h
@@ -13,13 +13,17 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
- 
+
 #ifndef _APXWIN_H_INCLUDED_
 #define _APXWIN_H_INCLUDED_
 
 
 #ifndef WIN32_LEAN_AND_MEAN
-#define WIN32_LEAN_AND_MEAN 
+#define WIN32_LEAN_AND_MEAN
+#endif
+
+#ifndef LOAD_LIBRARY_SEARCH_SYSTEM32
+#define	LOAD_LIBRARY_SEARCH_SYSTEM32	0x00000800
 #endif
 
 #include <windows.h>
@@ -73,12 +77,12 @@ typedef _W64 int            intptr_t;
 #define DYNLOAD_FPTR_ADDRESS(fnName, dllName)                       \
     FP_##fnName = (PFN_##fnName)GetProcAddress(                     \
                                 GetModuleHandle(TEXT(#dllName)),    \
-                                #fnName)    
+                                #fnName)
 
 #define DYNLOAD_FPTR_LOAD(fnName, dllHandle)                        \
     FP_##fnName = (PFN_##fnName)GetProcAddress(                     \
                                 dllHandle,                          \
-                                #fnName)    
+                                #fnName)
 
 #define DYNLOAD_CALL(fnName)    (*FP_##fnName)
 
diff --git a/src/native/windows/src/gui.c b/src/native/windows/src/gui.c
index 387fa1a..e4336f3 100644
--- a/src/native/windows/src/gui.c
+++ b/src/native/windows/src/gui.c
@@ -21,8 +21,6 @@
 /* Offset for listview dots */
 #define DOTOFFSET       0
 
-#define	LOAD_LIBRARY_SEARCH_SYSTEM32	0x00000800
-
 /* To harden against DLL hijacking, dynamic loading is used for any DLL that is
  * not one of the standard known DDLs pre-loaded by Windows.
  * Currently, the only DLL this applies to is NETAPI32.dll