Commit 1b7238a9 authored by James Hawkins's avatar James Hawkins Committed by Alexandre Julliard

msi: Simplify ITERATE_WriteEnvironmentString.

Now we only allocate enough memory to exactly match the size of the constructed string. Before, we were leaving some memory uninitialized and overwriting the allocated memory in certain circum.
parent be1b1605
......@@ -5013,7 +5013,24 @@ static UINT ITERATE_WriteEnvironmentString( MSIRECORD *rec, LPVOID param )
(res == ERROR_SUCCESS && type != REG_SZ && type != REG_EXPAND_SZ))
goto done;
if (res != ERROR_FILE_NOT_FOUND)
if ((res == ERROR_FILE_NOT_FOUND || !(flags & ENV_MOD_MASK)))
{
/* Nothing to do. */
if (!value)
{
res = ERROR_SUCCESS;
goto done;
}
size = (lstrlenW(value) + 1) * sizeof(WCHAR);
newval = strdupW(value);
if (!newval)
{
res = ERROR_OUTOFMEMORY;
goto done;
}
}
else
{
if (flags & ENV_ACT_SETABSENT)
{
......@@ -5038,8 +5055,18 @@ static UINT ITERATE_WriteEnvironmentString( MSIRECORD *rec, LPVOID param )
goto done;
}
size += (lstrlenW(value) + 1) * sizeof(WCHAR);
newval = msi_alloc(size);
size = (lstrlenW(data) + 1) * sizeof(WCHAR);
if (flags & ENV_MOD_MASK)
{
DWORD mod_size;
int multiplier = 0;
if (flags & ENV_MOD_APPEND) multiplier++;
if (flags & ENV_MOD_PREFIX) multiplier++;
mod_size = (lstrlenW(value) + 1) * multiplier;
size += mod_size * sizeof(WCHAR);
}
newval = msi_alloc(size);
ptr = newval;
if (!newval)
{
......@@ -5047,37 +5074,20 @@ static UINT ITERATE_WriteEnvironmentString( MSIRECORD *rec, LPVOID param )
goto done;
}
if (!(flags & ENV_MOD_MASK))
lstrcpyW(newval, value);
else
if (flags & ENV_MOD_PREFIX)
{
if (flags & ENV_MOD_PREFIX)
{
lstrcpyW(newval, value);
lstrcatW(newval, szSemiColon);
ptr = newval + lstrlenW(value) + 1;
}
lstrcpyW(newval, value);
lstrcatW(newval, szSemiColon);
ptr = newval + lstrlenW(value) + 1;
}
lstrcpyW(ptr, data);
lstrcpyW(ptr, data);
if (flags & ENV_MOD_APPEND)
{
lstrcatW(newval, szSemiColon);
lstrcatW(newval, value);
}
}
}
else if (value)
{
size = (lstrlenW(value) + 1) * sizeof(WCHAR);
newval = msi_alloc(size);
if (!newval)
if (flags & ENV_MOD_APPEND)
{
res = ERROR_OUTOFMEMORY;
goto done;
lstrcatW(newval, szSemiColon);
lstrcatW(newval, value);
}
lstrcpyW(newval, value);
}
if (newval)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment