Skip to contentSkip to conversation

clean up *sig_info handling in link_socket_init_phase2()

PATCH In review Gert Doering 2 participants 3 messages Nov 7, 2016 – Nov 8, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clean up *sig_info handling in link_socket_init_phase2()

The code was a mix of "assume that it is not NULL" and "check that it is not NULL before using" - it cannot be NULL (due to the single call graph, referencing c->sig with the global context), but for good measure, add an ASSERT() upon function entry and get rid of all the individual checks.

---
 src/openvpn/socket.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
src/openvpn/socket.c +6 -5
index 184c7ad..18e6409 100644
@@ -1857,8 +1857,9 @@ link_socket_init_phase2 (struct link_socket *sock,
   int sig_save = 0;
 
   ASSERT (sock);
+  ASSERT (sig_info);
 
-  if (sig_info && sig_info->signal_received)
+  if (sig_info->signal_received)
     {
       sig_save = sig_info->signal_received;
       sig_info->signal_received = 0;
@@ -1879,7 +1880,7 @@ link_socket_init_phase2 (struct link_socket *sock,
   if (sock->inetd)
     {
       phase2_inetd (sock, frame, remote_dynamic,  &sig_info->signal_received);
-      if (sig_info && sig_info->signal_received)
+      if (sig_info->signal_received)
 	goto done;
 
     }
@@ -1921,7 +1922,7 @@ link_socket_init_phase2 (struct link_socket *sock,
 	  goto done;
 	}
 
-      if (sig_info && sig_info->signal_received)
+      if (sig_info->signal_received)
 	goto done;
 
       if (sock->info.proto == PROTO_TCP_SERVER)
@@ -1942,7 +1943,7 @@ link_socket_init_phase2 (struct link_socket *sock,
       if (sock->sd != -1)
 	protect_fd_nonlocal (sock->sd, &sock->info.lsa->actual.dest.addr.sa);
 #endif
-      if (sig_info && sig_info->signal_received)
+      if (sig_info->signal_received)
 	goto done;
     }
 
@@ -1950,7 +1951,7 @@ link_socket_init_phase2 (struct link_socket *sock,
   linksock_print_addr(sock);
 
  done:
-  if (sig_save && sig_info)
+  if (sig_save)
     {
       if (!sig_info->signal_received)
 	sig_info->signal_received = sig_save;
Signature · 1 line
2.7.3
#1 lore raw
Quoted 55 lines · Gert Doering

The code was a mix of "assume that it is not NULL" and "check that it is not NULL before using" - it cannot be NULL (due to the single call graph, referencing c->sig with the global context), but for good measure, add an ASSERT() upon function entry and get rid of all the individual checks.

---
 src/openvpn/socket.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
src/openvpn/socket.c +5 -4
index 184c7ad..18e6409 100644
@@ -1857,8 +1857,9 @@ link_socket_init_phase2 (struct link_socket *sock,
   int sig_save = 0;
 
   ASSERT (sock);
+  ASSERT (sig_info);
 
-  if (sig_info && sig_info->signal_received)
+  if (sig_info->signal_received)
     {
       sig_save = sig_info->signal_received;
       sig_info->signal_received = 0;
@@ -1879,7 +1880,7 @@ link_socket_init_phase2 (struct link_socket *sock,
   if (sock->inetd)
     {
       phase2_inetd (sock, frame, remote_dynamic,  &sig_info->signal_received);
-      if (sig_info && sig_info->signal_received)
+      if (sig_info->signal_received)
 	goto done;
 
     }
@@ -1921,7 +1922,7 @@ link_socket_init_phase2 (struct link_socket *sock,
 	  goto done;
 	}
 
-      if (sig_info && sig_info->signal_received)
+      if (sig_info->signal_received)
 	goto done;
 
       if (sock->info.proto == PROTO_TCP_SERVER)
@@ -1942,7 +1943,7 @@ link_socket_init_phase2 (struct link_socket *sock,
       if (sock->sd != -1)
 	protect_fd_nonlocal (sock->sd, &sock->info.lsa->actual.dest.addr.sa);
 #endif
-      if (sig_info && sig_info->signal_received)
+      if (sig_info->signal_received)
 	goto done;
     }
 

src/openvpn/socket.c link_socket_init_phase2 (struct link_socket *sock, · line 1957

Quoted 8 lines
src/openvpn/socket.c +1 -1
@@ -1950,7 +1951,7 @@ link_socket_init_phase2 (struct link_socket *sock,
   linksock_print_addr(sock);
 
  done:
-  if (sig_save && sig_info)
+  if (sig_save)
     {
       if (!sig_info->signal_received)
 	sig_info->signal_received = sig_save;

ACK

-Steffan

#2 lore raw
In reply to Gert Doering

Patch has been applied to the master branch.

(I've added "Found by Coverity" to the commit message, code is unchanged)

commit 238cd6440312c59353a40a97b3c45d272561457f

Author: Gert Doering
Date:   Mon Nov 7 22:44:02 2016 +0100
     clean up *sig_info handling in link_socket_init_phase2()

     Signed-off-by: Gert Doering <[email protected]...>
     Acked-by: Steffan Karger <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg12931.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering