Ensure strings read from registry are null terminated

Signed-off-by: Selva Nair <selva.nair@gmail.com>
pull/33/head
Selva Nair 2016-03-30 20:57:34 -04:00
parent 4c8d5eaff0
commit ef9a195406
1 changed files with 9 additions and 1 deletions

View File

@ -241,6 +241,11 @@ int GetRegKey(const TCHAR name[], TCHAR *data, const TCHAR default_data[], DWORD
RegCloseKey(openvpn_key_write);
}
else
{
size /= sizeof(*data);
data[size - 1] = L'\0'; /* REG_SZ strings are not guaranteed to be null-terminated */
}
RegCloseKey(openvpn_key);
@ -264,7 +269,10 @@ LONG GetRegistryValue(HKEY regkey, const TCHAR *name, TCHAR *data, DWORD len)
if (status != ERROR_SUCCESS || type != REG_SZ)
return(0);
return(data_len / sizeof(*data));
data_len /= sizeof(*data);
data[data_len - 1] = L'\0'; /* REG_SZ strings are not guaranteed to be null-terminated */
return(data_len);
}