Browse Source

Ensure strings read from registry are null terminated

Signed-off-by: Selva Nair <selva.nair@gmail.com>
pull/33/head
Selva Nair 9 years ago
parent
commit
ef9a195406
  1. 10
      registry.c

10
registry.c

@ -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);
}

Loading…
Cancel
Save