Skip to content

Commit

Permalink
Fix ReadRegValue when data read from a registry key is of zero length
Browse files Browse the repository at this point in the history
Also if install_path read from registry is an empty string, illegal
memory access may result. Fix by using the default value in this
case as well.

Signed-off-by: Selva Nair <[email protected]>
  • Loading branch information
selvanair committed Feb 27, 2020
1 parent 2b10316 commit dd72345
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions registry.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ GetGlobalRegistryKeys()
regkey = NULL;
ShowLocalizedMsg(IDS_ERR_OPEN_REGISTRY);
}
if (!regkey || !GetRegistryValue(regkey, _T(""), openvpn_path, _countof(openvpn_path)))
if (!regkey || !GetRegistryValue(regkey, _T(""), openvpn_path, _countof(openvpn_path))
|| _tcslen(openvpn_path) == 0)
{
/* error reading registry value */
if (regkey)
Expand Down Expand Up @@ -369,7 +370,10 @@ LONG GetRegistryValue(HKEY regkey, const TCHAR *name, TCHAR *data, DWORD len)
return(0);

data_len /= sizeof(*data);
data[data_len - 1] = L'\0'; /* REG_SZ strings are not guaranteed to be null-terminated */
if (data_len > 0)
data[data_len - 1] = L'\0'; /* REG_SZ strings are not guaranteed to be null-terminated */
else
data[0] = L'\0';

return(data_len);

Expand Down

0 comments on commit dd72345

Please sign in to comment.