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/02 12:30:29 UTC

[commons-daemon] branch master updated: Partial fix for DAEMON-396

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 d761b82  Partial fix for DAEMON-396
d761b82 is described below

commit d761b82b8cb11409207809b79c9b491bc7559e81
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu May 2 13:24:57 2019 +0100

    Partial fix for DAEMON-396
    
    Fix a bug that meant a value provided for LibraryPath replaced the value
    of the PATH environment variable rather than prepended to it.
    Patch provided by Gerwin.
---
 src/changes/changes.xml        |  4 ++++
 src/native/windows/src/utils.c | 16 ++++++++--------
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 0c7dcab..3a6ccb1 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -58,6 +58,10 @@
       <action issue="DAEMON-392" type="fix" dev="ggregory" due-to="Daniel Hofmann">
         Undefined behaviour in registry.c dwRegKey = dwRegKey++
       </action>
+      <action issue="DAEMON-396" type="fix" dev="markt" due-to="Gerwin">
+        Fix a bug that meant a value provided for LibraryPath replaced the value
+        of the PATH environment variable rather than prepended to it.
+      </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/src/utils.c b/src/native/windows/src/utils.c
index b600917..2e0d2bf 100644
--- a/src/native/windows/src/utils.c
+++ b/src/native/windows/src/utils.c
@@ -60,17 +60,17 @@ BOOL apxAddToPathW(APXHANDLE hPool, LPCWSTR szAdd)
     LPWSTR wsAdd;
     DWORD  rc;
     DWORD  al;
-    
+
     rc = GetEnvironmentVariableW(L"PATH", NULL, 0);
     if (rc == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND)
         return FALSE;
-    al = lstrlenW(szAdd) + 6;
-    if (!(wsAdd = apxPoolAlloc(hPool, (al + rc + 1) * sizeof(WCHAR))))
+    al = 5 + lstrlenW(szAdd) + 1;
+    if (!(wsAdd = apxPoolAlloc(hPool, (al + rc) * sizeof(WCHAR))))
         return FALSE;
-    lstrcpyW(wsAdd, L"PATH=");        
-    lstrcatW(wsAdd, szAdd);        
-    lstrcatW(wsAdd, L";");        
-    if (!GetEnvironmentVariableW(L"PATH", wsAdd + al, rc - al)) {
+    lstrcpyW(wsAdd, L"PATH=");
+    lstrcatW(wsAdd, szAdd);
+    lstrcatW(wsAdd, L";");
+    if (GetEnvironmentVariableW(L"PATH", wsAdd + al, rc) != rc - 1) {
         apxLogWrite(APXLOG_MARK_SYSERR);
         apxFree(wsAdd);
         return FALSE;
@@ -346,7 +346,7 @@ apxStrCharReplaceA(LPSTR szString, CHAR chReplace, CHAR chReplaceWith)
 {
   LPSTR p = szString;
   LPSTR q = szString;
-  
+
   if (IS_EMPTY_STRING(szString))
     return;
   while (*p) {