Skip to content
Closed
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
4 changes: 4 additions & 0 deletions google/cloud/internal/curl_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,10 @@ Status CurlImpl::MakeRequestImpl(RestContext& context) {
if (!status.ok()) return OnTransferError(context, std::move(status));
handle_.SetSocketCallback(socket_options_);
if (!status.ok()) return OnTransferError(context, std::move(status));
status = handle_.SetOption(CURLOPT_SSL_EC_CURVES, "X25519MLKEM768:X25519:P-256:P-384");
if (!status.ok()) {
GCP_LOG(INFO) << "CURLOPT_SSL_EC_CURVES failed: " << status;
}
Comment on lines +604 to +607

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Reusing the status variable for an option whose failure is explicitly ignored is risky. If CURLOPT_SSL_EC_CURVES fails, status is left in a non-OK state until it is overwritten by the next SetOption call. If the code is refactored, reordered, or if another check is inserted in between, this temporary error state could be accidentally propagated or returned.

Using a separate local variable (e.g., ec_status) avoids polluting the main status variable and makes the intent to ignore the failure much clearer and safer.

  auto ec_status = handle_.SetOption(CURLOPT_SSL_EC_CURVES, "X25519MLKEM768:X25519:P-256:P-384");
  if (!ec_status.ok()) {
    GCP_LOG(INFO) << "CURLOPT_SSL_EC_CURVES failed: " << ec_status;
  }
References
  1. Prefer defensive code, such as explicit ok() checks, even if they seem redundant based on the current implementation of a framework, as the framework's contract may change in the future.

status = handle_.SetOption(CURLOPT_NOSIGNAL, 1);
if (!status.ok()) return OnTransferError(context, std::move(status));
status = handle_.SetOption(CURLOPT_TCP_KEEPALIVE, 1L);
Expand Down
Loading