Skip to content
Draft
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions runtime/shims/winhttp_offline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,10 @@ HINTERNET WINAPI open_connection(HINTERNET session, LPCWSTR server, INTERNET_POR
return nullptr;
}
if (!server || !*server) {
// As the host's winhttp.dll answers (measured on Windows 11): no name is ERROR_INVALID_PARAMETER, an empty
// one ERROR_WINHTTP_INVALID_URL.
release(s);
SetLastError(ERROR_INVALID_PARAMETER);
SetLastError(server ? ERROR_WINHTTP_INVALID_URL : ERROR_INVALID_PARAMETER);
return nullptr;
}
return make_handle(Kind::Connect, s, s->async, server, port); // keeps the reference on the session
Expand Down Expand Up @@ -342,7 +344,7 @@ BOOL WINAPI set_option(HINTERNET handle, DWORD option, LPVOID buffer, DWORD leng
release(h);
return fail(ERROR_INVALID_PARAMETER);
}
if (length < sizeof(DWORD_PTR)) {
if (length != sizeof(DWORD_PTR)) { // the host takes exactly a DWORD_PTR: 4 and 16 bytes both fail (measured)
release(h);
return fail(ERROR_INSUFFICIENT_BUFFER);
}
Expand Down
15 changes: 15 additions & 0 deletions runtime/test/winhttp_offline_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,18 @@ int main() {
check(set_option(request, WINHTTP_OPTION_CONTEXT_VALUE, &short_ctx, sizeof(short_ctx)) == FALSE &&
GetLastError() == ERROR_INSUFFICIENT_BUFFER,
"a 4-byte WINHTTP_OPTION_CONTEXT_VALUE fails with ERROR_INSUFFICIENT_BUFFER");
const DWORD_PTR long_ctx[2] = {0x5678, 0x9abc};
SetLastError(0);
check(set_option(request, WINHTTP_OPTION_CONTEXT_VALUE, const_cast<DWORD_PTR*>(long_ctx), sizeof(long_ctx)) ==
FALSE &&
GetLastError() == ERROR_INSUFFICIENT_BUFFER,
"a 16-byte WINHTTP_OPTION_CONTEXT_VALUE fails with ERROR_INSUFFICIENT_BUFFER too, as on the host");
{
DWORD_PTR kept = 0;
DWORD kept_size = sizeof(kept);
check(query_option(request, WINHTTP_OPTION_CONTEXT_VALUE, &kept, &kept_size) != FALSE && kept == 0x1234,
"and the context set before stays");
}
SetLastError(0);
check(set_option(nullptr, WINHTTP_OPTION_CONTEXT_VALUE, &value, sizeof(value)) == FALSE &&
GetLastError() == ERROR_WINHTTP_INCORRECT_HANDLE_TYPE,
Expand All @@ -364,6 +376,9 @@ int main() {
SetLastError(0);
check(connect(session, nullptr, 80, 0) == nullptr && GetLastError() == ERROR_INVALID_PARAMETER,
"a connection needs a server name");
SetLastError(0);
check(connect(session, L"", 80, 0) == nullptr && GetLastError() == ERROR_WINHTTP_INVALID_URL,
"an empty server name fails with ERROR_WINHTTP_INVALID_URL, as on the host");

check(close(request) != FALSE && close(connection) != FALSE && close(session) != FALSE,
"the handles close, children first");
Expand Down