Skip to content

Commit

Permalink
Ensure request buffer is available for WinHTTP.
Browse files Browse the repository at this point in the history
Bug: 1383611
Change-Id: I5bd138a8b2e0c80de686f655e93bbfe254e3b1a6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4024532
Auto-Submit: Xiaoling Bao <xiaolingbao@chromium.org>
Reviewed-by: Sorin Jianu <sorin@chromium.org>
Commit-Queue: Sorin Jianu <sorin@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1070627}
  • Loading branch information
gxbao authored and Chromium LUCI CQ committed Nov 12, 2022
1 parent b2a4b6f commit 3d98e16
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
11 changes: 8 additions & 3 deletions components/winhttp/network_fetcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,14 @@ HRESULT NetworkFetcher::SendRequest(const std::string& data) {

VLOG(2) << data;

const uint32_t bytes_to_send = base::saturated_cast<uint32_t>(data.size());
void* request_body =
bytes_to_send ? const_cast<char*>(data.c_str()) : WINHTTP_NO_REQUEST_DATA;
// Make a copy of the request data to ensure the buffer is available until
// the request is processed.
request_data_ = data;

const uint32_t bytes_to_send =
base::saturated_cast<uint32_t>(request_data_.size());
void* request_body = bytes_to_send ? const_cast<char*>(request_data_.c_str())
: WINHTTP_NO_REQUEST_DATA;
if (!::WinHttpSendRequest(request_handle_.get(),
WINHTTP_NO_ADDITIONAL_HEADERS, 0, request_body,
bytes_to_send, bytes_to_send, context())) {
Expand Down
1 change: 1 addition & 0 deletions components/winhttp/network_fetcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class NetworkFetcher : public base::RefCountedThreadSafe<NetworkFetcher> {
std::string path_for_request_;

base::WStringPiece verb_;
std::string request_data_;
// The value of Content-Type header, e.g. "application/json".
std::string content_type_;
WriteDataCallback write_data_callback_;
Expand Down

0 comments on commit 3d98e16

Please sign in to comment.