swrap: Add paranoia NULL checks
authorAndreas Schneider <asn@samba.org>
Fri, 15 Mar 2019 13:59:14 +0000 (14:59 +0100)
committerAndreas Schneider <asn@samba.org>
Thu, 21 Mar 2019 07:42:57 +0000 (08:42 +0100)
csbuild complains about missing NULL checks here.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
src/socket_wrapper.c

index 193f1f0672d2e0d883a4aeaaeba2fb29e238b1b4..7841c858dd82e85708b2f124ee29e8e17bf5ed5b 100644 (file)
@@ -2572,6 +2572,11 @@ static uint8_t *swrap_pcap_packet_init(struct timeval *tval,
        i.ptr = buf;
        switch (src->sa_family) {
        case AF_INET:
+               if (src_in == NULL || dest_in == NULL) {
+                       SAFE_FREE(base);
+                       return NULL;
+               }
+
                i.ip->v4.ver_hdrlen     = 0x45; /* version 4 and 5 * 32 bit words */
                i.ip->v4.tos            = 0x00;
                i.ip->v4.packet_length  = htons(wire_len - icmp_truncate_len);
@@ -2587,6 +2592,11 @@ static uint8_t *swrap_pcap_packet_init(struct timeval *tval,
                break;
 #ifdef HAVE_IPV6
        case AF_INET6:
+               if (src_in6 == NULL || dest_in6 == NULL) {
+                       SAFE_FREE(base);
+                       return NULL;
+               }
+
                i.ip->v6.ver_prio               = 0x60; /* version 4 and 5 * 32 bit words */
                i.ip->v6.flow_label_high        = 0x00;
                i.ip->v6.flow_label_low = 0x0000;