Zebediah Figura : msi: Check for a NULL return from deformat_string() when checking for failure.

Alexandre Julliard julliard at winehq.org
Tue Oct 26 09:40:27 CDT 2021


Module: wine
Branch: stable
Commit: 5703c141108c41ac5d3d21cc30aa28007f9f8d4f
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=5703c141108c41ac5d3d21cc30aa28007f9f8d4f

Author: Zebediah Figura <z.figura12 at gmail.com>
Date:   Sun May  2 21:42:47 2021 -0500

msi: Check for a NULL return from deformat_string() when checking for failure.

An empty string is valid, and can occur if e.g. a nonexistent property is
expanded.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51091
Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
Signed-off-by: Hans Leidekker <hans at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
(cherry picked from commit 814f18ab756cd69158ce893c4f7898e14d3e46dc)
Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>

---

 dlls/msi/action.c       | 69 ++++++++++++++++++++++++++++++++-----------------
 dlls/msi/tests/action.c |  8 +++++-
 2 files changed, 52 insertions(+), 25 deletions(-)

diff --git a/dlls/msi/action.c b/dlls/msi/action.c
index cc5d56fdc2b..4217e0efe85 100644
--- a/dlls/msi/action.c
+++ b/dlls/msi/action.c
@@ -6790,25 +6790,34 @@ static UINT ITERATE_WriteEnvironmentString( MSIRECORD *rec, LPVOID param )
     if (res != ERROR_SUCCESS || !value)
        goto done;
 
-    if (value && !deformat_string(package, value, &deformatted))
+    if (value)
     {
-        res = ERROR_OUTOFMEMORY;
-        goto done;
-    }
+        DWORD len = deformat_string( package, value, &deformatted );
+        if (!deformatted)
+        {
+            res = ERROR_OUTOFMEMORY;
+            goto done;
+        }
 
-    if ((value = deformatted))
-    {
-        if (flags & ENV_MOD_PREFIX)
+        if (len)
         {
-            p = wcsrchr( value, ';' );
-            len_value = p - value;
+            value = deformatted;
+            if (flags & ENV_MOD_PREFIX)
+            {
+                p = wcsrchr( value, ';' );
+                len_value = p - value;
+            }
+            else if (flags & ENV_MOD_APPEND)
+            {
+                value = wcschr( value, ';' ) + 1;
+                len_value = lstrlenW( value );
+            }
+            else len_value = lstrlenW( value );
         }
-        else if (flags & ENV_MOD_APPEND)
+        else
         {
-            value = wcschr( value, ';' ) + 1;
-            len_value = lstrlenW( value );
+            value = NULL;
         }
-        else len_value = lstrlenW( value );
     }
 
     res = open_env_key( flags, &env );
@@ -6997,22 +7006,34 @@ static UINT ITERATE_RemoveEnvironmentString( MSIRECORD *rec, LPVOID param )
         return ERROR_SUCCESS;
     }
 
-    if (value && !deformat_string( package, value, &deformatted ))
-        return ERROR_OUTOFMEMORY;
-
-    if ((value = deformatted))
+    if (value)
     {
-        if (flags & ENV_MOD_PREFIX)
+        DWORD len = deformat_string( package, value, &deformatted );
+        if (!deformatted)
+        {
+            res = ERROR_OUTOFMEMORY;
+            goto done;
+        }
+
+        if (len)
         {
-            p = wcschr( value, ';' );
-            len_value = p - value;
+            value = deformatted;
+            if (flags & ENV_MOD_PREFIX)
+            {
+                p = wcsrchr( value, ';' );
+                len_value = p - value;
+            }
+            else if (flags & ENV_MOD_APPEND)
+            {
+                value = wcschr( value, ';' ) + 1;
+                len_value = lstrlenW( value );
+            }
+            else len_value = lstrlenW( value );
         }
-        else if (flags & ENV_MOD_APPEND)
+        else
         {
-            value = wcschr( value, ';' ) + 1;
-            len_value = lstrlenW( value );
+            value = NULL;
         }
-        else len_value = lstrlenW( value );
     }
 
     r = open_env_key( flags, &env );
diff --git a/dlls/msi/tests/action.c b/dlls/msi/tests/action.c
index 48866e36f44..d1396ed0110 100644
--- a/dlls/msi/tests/action.c
+++ b/dlls/msi/tests/action.c
@@ -249,7 +249,9 @@ static const char env_environment_dat[] =
     "Var27\t+-MSITESTVAR21\t[~];1\tOne\n"
     "Var28\t-MSITESTVAR22\t1\tOne\n"
     "Var29\t-MSITESTVAR23\t2\tOne\n"
-    "Var30\t*MSITESTVAR100\t1\tOne\n";
+    "Var30\t*MSITESTVAR100\t1\tOne\n"
+    "Var31\t-=MSITESTVAR24\t[SERVNAME]\tOne\n"
+    "Var32\t-=MSITESTVAR25\t[bogus_prop]\tOne\n";
 
 static const char service_install_dat[] =
     "ServiceInstall\tName\tDisplayName\tServiceType\tStartType\tErrorControl\t"
@@ -5050,6 +5052,7 @@ static void test_envvar(void)
     CHECK_REG_STR(env, "MSITESTVAR19", "1");
     CHECK_REG_STR(env, "MSITESTVAR20", "1");
     CHECK_REG_STR(env, "MSITESTVAR21", "1");
+    CHECK_REG_STR(env, "MSITESTVAR24", "TestService");
     CHECK_REG_STR(env2, "MSITESTVAR100", "1");
 
     res = RegSetValueExA(env, "MSITESTVAR22", 0, REG_SZ, (const BYTE *)"1", 2);
@@ -5058,6 +5061,9 @@ static void test_envvar(void)
     res = RegSetValueExA(env, "MSITESTVAR23", 0, REG_SZ, (const BYTE *)"1", 2);
     ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
 
+    res = RegDeleteValueA(env, "MSITESTVAR25");
+    ok(res == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", res);
+
     r = MsiInstallProductA(msifile, "REMOVE=ALL");
     ok(!r, "got %u\n", r);
 




More information about the wine-cvs mailing list