Skip to contentSkip to conversation

Fix using a pointer before checking against null

PATCH New SviMik 1 participant 1 message Nov 25, 2016

lore
Share & tools
lore

SviMik

author
#0 lore raw

PATCH 1/1 Fix using a pointer before checking against null

There was a few places where pointer was used and then checked against null.

This patch is trying to fix that by adding additional checks or moving it into the right place.

---
 src/openvpn/buffer.c |    2 +-
 src/openvpn/ps.c     |    4 ++--
 src/openvpn/push.c   |    2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
src/openvpn/buffer.c +1 -1
index 52c6ab9..57956dd 100644
@@ -439,7 +439,7 @@ format_hex_ex (const uint8_t *data, int size, int maxoutput,
 	       struct gc_arena *gc)
 {
   struct buffer out = alloc_buf_gc (maxoutput ? maxoutput :
-				    ((size * 2) + (size / (space_break_flags & FHE_SPACE_BREAK_MASK)) * (int) strlen (separator) + 2),
+				    ((size * 2) + (size / (space_break_flags & FHE_SPACE_BREAK_MASK)) * (separator ? (int) strlen (separator) : 0) + 2),
 				    gc);
   int i;
   for (i = 0; i < size; ++i)
src/openvpn/ps.c +2 -2
index 2cb68f1..935bd0b 100644
@@ -499,6 +499,7 @@ control_message_from_parent (const socket_descriptor_t sd_control,
   mesg.msg_flags = 0;
 
   h = CMSG_FIRSTHDR(&mesg);
+  ASSERT (h);
   h->cmsg_len = CMSG_LEN(sizeof(socket_descriptor_t));
   h->cmsg_level = SOL_SOCKET;
   h->cmsg_type = SCM_RIGHTS;
@@ -508,8 +509,7 @@ control_message_from_parent (const socket_descriptor_t sd_control,
   status = recvmsg (sd_control, &mesg, MSG_NOSIGNAL);
   if (status != -1)
     {
-      if (   h == NULL
-	  || h->cmsg_len    != CMSG_LEN(sizeof(socket_descriptor_t))
+      if ( h->cmsg_len    != CMSG_LEN(sizeof(socket_descriptor_t))
 	  || h->cmsg_level  != SOL_SOCKET
 	  || h->cmsg_type   != SCM_RIGHTS )
 	{
src/openvpn/push.c +1 -1
index 9953079..b016d99 100644
@@ -565,7 +565,7 @@ push_remove_option (struct options *o, const char *p)
   msg (D_PUSH_DEBUG, "PUSH_REMOVE searching for: '%s'", p);
 
   /* ifconfig-ipv6 is special, as not part of the push list */
-  if ( streq( p, "ifconfig-ipv6" ))
+  if (o && streq( p, "ifconfig-ipv6" ))
     {
       o->push_ifconfig_ipv6_blocked = true;
       return;
Signature · 1 line
1.7.10.msysgit.1