connect: Avoid calling close with negative argument

The `first` is intialized to -1 and if we reach this without setting this, we
needlessly call close(-1). It should be no-op, but better be safe.

Thanks coverity!

CID 1644001

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Jakub Jelen
2026-01-07 13:25:25 +01:00
parent 48fdf4b80a
commit c9abf5ebbb

View File

@@ -335,8 +335,8 @@ socket_t ssh_connect_host_nonblocking(ssh_session session, const char *host,
* connection, otherwise return the first address without error or error */ * connection, otherwise return the first address without error or error */
if (s == -1) { if (s == -1) {
s = first; s = first;
} else if (s != first) { } else if (s != first && first != -1) {
/* Clean up the saved socket */ /* Clean up the saved socket if any */
ssh_connect_socket_close(first); ssh_connect_socket_close(first);
} }