]> www.infradead.org Git - users/dwmw2/openconnect.git/commitdiff
Manual fixes based on clang static analysis
authorDimitri Papadopoulos Orfanos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
Thu, 18 Sep 2025 22:28:02 +0000 (00:28 +0200)
committerDimitri Papadopoulos Orfanos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
Fri, 19 Sep 2025 17:17:53 +0000 (19:17 +0200)
Signed-off-by: Dimitri Papadopoulos Orfanos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
auth-juniper.c
dtls.c
esp.c
library.c
main.c
mainloop.c
ppp.c
pulse.c
ssl.c
tun.c
vhost.c

index 814412cd3a3746bb7526005c2cea4ea9a122bd1d..009b0f091226470f564f3960ad2dd2ceb107f729 100644 (file)
@@ -145,7 +145,7 @@ static int check_cookie_success(struct openconnect_info *vpninfo)
        if (!dsid)
                return -ENOENT;
 
-       if (vpninfo->tncc_fd != -1) {
+       if (vpninfo->tncc_fd >= 0) {
                /* update TNCC once we get a DSID cookie */
                oncp_send_tncc_command(vpninfo, 0);
        }
diff --git a/dtls.c b/dtls.c
index 427109e873989ea6e4759083a3827a223dbab69e..2e723f2abeacb2e1c53350afdfd529b0794b4603 100644 (file)
--- a/dtls.c
+++ b/dtls.c
@@ -101,7 +101,7 @@ static int connect_dtls_socket(struct openconnect_info *vpninfo, int *timeout)
        int dtls_fd, ret;
 
        /* Sanity check for the removal of new_dtls_{fd,ssl} */
-       if (vpninfo->dtls_fd != -1) {
+       if (vpninfo->dtls_fd >= 0) {
                vpn_progress(vpninfo, PRG_ERR, _("DTLS connection attempted with an existing fd\n"));
                vpninfo->dtls_attempt_period = 0;
                return -EINVAL;
diff --git a/esp.c b/esp.c
index 33f586492f0c25d6a053bba7c11b05457d257954..6407e59f9af9ff6cda622b02dc6895ad38aad284 100644 (file)
--- a/esp.c
+++ b/esp.c
@@ -144,7 +144,7 @@ int esp_mainloop(struct openconnect_info *vpninfo, int *timeout, int readable)
           reserve some extra space to handle that */
        int receive_mtu = MAX(2048, vpninfo->ip_info.mtu + 256);
 
-       while (readable && vpninfo->dtls_fd != -1) {
+       while (readable && vpninfo->dtls_fd >= 0) {
                int len = receive_mtu + vpninfo->pkt_trailer;
                int i;
                struct pkt *pkt;
index 5185f03522aa4f4b1d3e019f6643148810e7eacc..b5e74e9b765b5b146a0af841b8198047ca8dbb7e 100644 (file)
--- a/library.c
+++ b/library.c
@@ -773,9 +773,9 @@ void openconnect_vpninfo_free(struct openconnect_info *vpninfo)
        openconnect_close_https(vpninfo, 1);
        if (vpninfo->proto->udp_shutdown)
                vpninfo->proto->udp_shutdown(vpninfo);
-       if (vpninfo->tncc_fd != -1)
+       if (vpninfo->tncc_fd >= 0)
                closesocket(vpninfo->tncc_fd);
-       if (vpninfo->cmd_fd_write != -1) {
+       if (vpninfo->cmd_fd_write >= 0) {
                closesocket(vpninfo->cmd_fd);
                closesocket(vpninfo->cmd_fd_write);
        }
diff --git a/main.c b/main.c
index 4fb6818fd013394896fec79109becde5b65707b2..6c21796b7abf562e47353bd093db6407e73cce75 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1688,7 +1688,7 @@ static void print_connection_stats(void *_vpninfo, const struct oc_stats *stats)
                     _("RX: %"PRIu64" packets (%"PRIu64" B); TX: %"PRIu64" packets (%"PRIu64" B)\n"),
                       stats->rx_pkts, stats->rx_bytes, stats->tx_pkts, stats->tx_bytes);
 
-       if (vpninfo->ssl_fd != -1)
+       if (vpninfo->ssl_fd >= 0)
                vpn_progress(vpninfo, PRG_INFO, _("SSL ciphersuite: %s\n"), openconnect_get_cstp_cipher(vpninfo));
        if (vpninfo->dtls_state == DTLS_CONNECTED)
                vpn_progress(vpninfo, PRG_INFO, _("%s ciphersuite: %s\n"),
index 32bddcdaca1cc94c3ba6e0f026181f2daa3b5cf7..f4babc7c627120536f04f8b9e49565875d175061 100644 (file)
@@ -176,7 +176,7 @@ int openconnect_mainloop(struct openconnect_info *vpninfo,
        vpninfo->reconnect_timeout = reconnect_timeout;
        vpninfo->reconnect_interval = reconnect_interval;
 
-       if (vpninfo->cmd_fd != -1) {
+       if (vpninfo->cmd_fd >= 0) {
                monitor_fd_new(vpninfo, cmd);
                monitor_read_fd(vpninfo, cmd);
        }
@@ -234,7 +234,7 @@ int openconnect_mainloop(struct openconnect_info *vpninfo,
                        while ((this = dequeue_packet(&vpninfo->incoming_queue)))
                                free_pkt(vpninfo, this);
 #ifdef HAVE_VHOST
-               } else if (vpninfo->vhost_fd != -1) {
+               } else if (vpninfo->vhost_fd >= 0) {
                        did_work += vhost_tun_mainloop(vpninfo, &timeout, vhost_r, did_work);
                        /* If it returns zero *then* it will have read the eventfd
                         * and there's no need to do so again until we poll again. */
diff --git a/ppp.c b/ppp.c
index e01ed7197caff09cbf764ffef3f45c5391ad2fbc..f121d0891677b135f21aba39ed2873a75007a65c 100644 (file)
--- a/ppp.c
+++ b/ppp.c
@@ -1568,7 +1568,7 @@ int ppp_tcp_mainloop(struct openconnect_info *vpninfo, int *timeout, int readabl
        /* If we're still attempting DTLS, do nothing yet. */
        switch (vpninfo->dtls_state) {
        case DTLS_ESTABLISHED:
-               if (vpninfo->ssl_fd != -1) {
+               if (vpninfo->ssl_fd >= 0) {
                        openconnect_close_https(vpninfo, 0); /* don't keep stale HTTPS socket */
                        vpn_progress(vpninfo, PRG_INFO,
                                     _("DTLS tunnel connected; exiting HTTPS mainloop.\n"));
@@ -1615,7 +1615,7 @@ int ppp_tcp_mainloop(struct openconnect_info *vpninfo, int *timeout, int readabl
                 * gets invoked. When f5_connect() actually establishes the tunnel,
                 * it does so to start the PPP state machine for the TCP connection.
                 */
-               if (vpninfo->ssl_fd != -1 && vpninfo->ppp->ppp_state != PPPS_DEAD)
+               if (vpninfo->ssl_fd >= 0 && vpninfo->ppp->ppp_state != PPPS_DEAD)
                        return ppp_mainloop(vpninfo, 0, &vpninfo->ssl_times, timeout, readable);
 
                /* This will call *back* into the protocol's ->tcp_connect()
diff --git a/pulse.c b/pulse.c
index e8dd9b7c039c6a4fdcf4b7198d69030871c09da0..6d09bdc4dd02f8e6a41d0cf5998df8423f863dd9 100644 (file)
--- a/pulse.c
+++ b/pulse.c
@@ -3146,7 +3146,7 @@ int pulse_mainloop(struct openconnect_info *vpninfo, int *timeout, int readable)
 int pulse_bye(struct openconnect_info *vpninfo, const char *reason)
 {
        int ret = -1;
-       if (vpninfo->ssl_fd != -1) {
+       if (vpninfo->ssl_fd >= 0) {
                struct oc_text_buf *buf = buf_alloc();
                buf_append_ift_hdr(buf, VENDOR_JUNIPER, 0x89);
                if (!buf_error(buf))
diff --git a/ssl.c b/ssl.c
index a3db7869f705d48faeaa1a68999808920e5cf5a5..b64c8979b5f2d267b4834ae4a34c97a0b20541b7 100644 (file)
--- a/ssl.c
+++ b/ssl.c
@@ -867,7 +867,7 @@ int keystore_fetch(const char *key, unsigned char **result)
 
 void cmd_fd_set(struct openconnect_info *vpninfo, fd_set *fds, int *maxfd)
 {
-       if (vpninfo->cmd_fd != -1) {
+       if (vpninfo->cmd_fd >= 0) {
                FD_SET(vpninfo->cmd_fd, fds);
                if (vpninfo->cmd_fd > *maxfd)
                        *maxfd = vpninfo->cmd_fd;
diff --git a/tun.c b/tun.c
index 7cd977d5396166b7001b447107c1f2956f352d94..234f980d608a0bb0008391102718d79e73c87545 100644 (file)
--- a/tun.c
+++ b/tun.c
@@ -442,7 +442,7 @@ int openconnect_setup_tun_fd(struct openconnect_info *vpninfo, int tun_fd)
 {
        set_fd_cloexec(tun_fd);
 
-       if (vpninfo->tun_fd != -1)
+       if (vpninfo->tun_fd >= 0)
                unmonitor_fd(vpninfo, tun);
 
        vpninfo->tun_fd = tun_fd;
@@ -580,7 +580,7 @@ void os_shutdown_tun(struct openconnect_info *vpninfo)
 #ifdef __sun__
                close(vpninfo->ip_fd);
                vpninfo->ip_fd = -1;
-               if (vpninfo->ip6_fd != -1) {
+               if (vpninfo->ip6_fd >= 0) {
                        close(vpninfo->ip6_fd);
                        vpninfo->ip6_fd = -1;
                }
diff --git a/vhost.c b/vhost.c
index 408010bdaabc859e4e8f6328f04aa69805cc8d18..ae19c3f895e6079b66ed15dbeacbe80a4924e6ed 100644 (file)
--- a/vhost.c
+++ b/vhost.c
@@ -383,11 +383,11 @@ static void free_vring(struct openconnect_info *vpninfo,
 
 void shutdown_vhost(struct openconnect_info *vpninfo)
 {
-       if (vpninfo->vhost_fd != -1)
+       if (vpninfo->vhost_fd >= 0)
                close(vpninfo->vhost_fd);
-       if (vpninfo->vhost_kick_fd != -1)
+       if (vpninfo->vhost_kick_fd >= 0)
                close(vpninfo->vhost_kick_fd);
-       if (vpninfo->vhost_call_fd != -1)
+       if (vpninfo->vhost_call_fd >= 0)
                close(vpninfo->vhost_call_fd);
 
        vpninfo->vhost_fd = vpninfo->vhost_kick_fd = vpninfo->vhost_call_fd = -1;