Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions src/coreclr/vm/hostinformation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,38 @@ bool HostInformation::GetProperty(_In_z_ const char* name, SString& value)
return false;

size_t len = MAX_PATH + 1;
char* dest = value.OpenUTF8Buffer(static_cast<COUNT_T>(len));
char* dest = value.OpenUTF8Buffer(static_cast<COUNT_T>(len) - 1); // OpenUTF8Buffer already includes a byte for the null terminator
// get_runtime_property returns the length including a null terminator
size_t lenActual = s_hostContract.get_runtime_property(name, dest, len, s_hostContract.context);
value.CloseBuffer();

// Doesn't exist or failed to get property
if (lenActual == (size_t)-1 || lenActual == 0)
{
value.CloseBuffer(0);
return false;
}

if (lenActual <= len)
{
value.CloseBuffer(static_cast<COUNT_T>(lenActual) - 1);
return true;
}

value.CloseBuffer();

// Buffer was not large enough
len = lenActual;
dest = value.OpenUTF8Buffer(static_cast<COUNT_T>(len));
dest = value.OpenUTF8Buffer(static_cast<COUNT_T>(len) - 1); // OpenUTF8Buffer already includes a byte for the null terminator
lenActual = s_hostContract.get_runtime_property(name, dest, len, s_hostContract.context);
value.CloseBuffer();

return lenActual > 0 && lenActual <= len;
if (lenActual == (size_t)-1 || lenActual == 0 || lenActual > len)
{
value.CloseBuffer(0);
return false;
}

value.CloseBuffer(static_cast<COUNT_T>(lenActual) - 1);
return true;
}

bool HostInformation::HasExternalProbe()
Expand Down
Loading