Skip to content

Commit

Permalink
Coverity fixes P173127397
Browse files Browse the repository at this point in the history
  • Loading branch information
skmcgrail committed Nov 26, 2024
1 parent 412018d commit 3edbb35
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
18 changes: 15 additions & 3 deletions tool/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@

#if !defined(OPENSSL_WINDOWS)
#include <sys/select.h>
#include <unistd.h>
#define close_socket close
#else
OPENSSL_MSVC_PRAGMA(warning(push, 3))
#include <winsock2.h>
OPENSSL_MSVC_PRAGMA(warning(pop))
#define close_socket closesocket
#endif

#include <openssl/err.h>
Expand Down Expand Up @@ -318,8 +321,11 @@ static bool DoConnection(SSL_CTX *ctx,
bool (*cb)(SSL *ssl, int sock), bool is_openssl_s_client) {
int sock = -1;
if (args_map.count("-http-tunnel") != 0) {
if (!Connect(&sock, args_map["-http-tunnel"], is_openssl_s_client) ||
!DoHTTPTunnel(sock, args_map["-connect"])) {
if (!Connect(&sock, args_map["-http-tunnel"], is_openssl_s_client)) {
return false;
}
if (!DoHTTPTunnel(sock, args_map["-connect"])) {
close_socket(sock);
return false;
}
} else if (!Connect(&sock, args_map["-connect"], is_openssl_s_client)) {
Expand All @@ -335,19 +341,25 @@ static bool DoConnection(SSL_CTX *ctx,
const std::string& starttls = args_map["-starttls"];
if (starttls == "smtp") {
if (!DoSMTPStartTLS(sock)) {
close_socket(sock);
return false;
}
} else {
close_socket(sock);
fprintf(stderr, "Unknown value for -starttls: %s\n", starttls.c_str());
return false;
}
}

// BIO takes ownership of |sock| from this point forward.
bssl::UniquePtr<BIO> bio(BIO_new_socket(sock, BIO_CLOSE));
bssl::UniquePtr<SSL> ssl(SSL_new(ctx));

if (args_map.count("-server-name") != 0) {
SSL_set_tlsext_host_name(ssl.get(), args_map["-server-name"].c_str());
if (!SSL_set_tlsext_host_name(ssl.get(),
args_map["-server-name"].c_str())) {
return false;
}
}

if (args_map.count("-ech-grease") != 0) {
Expand Down
1 change: 1 addition & 0 deletions tool/transport_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ bool Connect(int *out_sock, const std::string &hostname_and_port, bool quiet) {

if (connect(*out_sock, result->ai_addr, result->ai_addrlen) != 0) {
PrintSocketError("connect");
close(*out_sock);
goto out;
}
ok = true;
Expand Down

0 comments on commit 3edbb35

Please sign in to comment.