[SCM] Socket Wrapper Repository - branch master updated

Andreas Schneider asn at samba.org
Thu Mar 21 07:43:18 UTC 2019


The branch, master has been updated
       via  bd951c1 swrap: Add paranoia NULL checks
       via  6e1ed1d swrap: Fix strict aliasing issues in swrap_pcap_packet_init()
       via  2cfe068 swrap: Fix "Value stored never used" warning
       via  6f69593 tests: Fix typo in echo_srv help
       via  887ce58 doc: Fix some typos in the manpage
      from  2d53497 swrap: Do not use FALL_THROUGH for empty case statements

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit bd951c1f6944011bb5585cb58c92ca5cd5b78489
Author: Andreas Schneider <asn at samba.org>
Date:   Fri Mar 15 14:59:14 2019 +0100

    swrap: Add paranoia NULL checks
    
    csbuild complains about missing NULL checks here.
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 6e1ed1da3f4372b7de69c5f8be227d85727b2b59
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Feb 28 13:00:40 2019 +0100

    swrap: Fix strict aliasing issues in swrap_pcap_packet_init()
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 2cfe0686137c61edd2ff9c6fa01e5499d210c0c5
Author: Anoop C S <anoopcs at redhat.com>
Date:   Fri Mar 15 18:48:40 2019 +0530

    swrap: Fix "Value stored never used" warning
    
    Signed-off-by: Anoop C S <anoopcs at redhat.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 6f69593669b7d8424492da95a58d4d7cffa3c974
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Feb 28 13:02:35 2019 +0100

    tests: Fix typo in echo_srv help
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 887ce58dff7d8325e01738bd099e57dbace469f8
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Feb 28 13:02:08 2019 +0100

    doc: Fix some typos in the manpage
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 doc/socket_wrapper.1     |   6 +--
 doc/socket_wrapper.1.txt |   8 +--
 src/socket_wrapper.c     | 123 +++++++++++++++++++++++++++--------------------
 tests/echo_srv.c         |   2 +-
 4 files changed, 79 insertions(+), 60 deletions(-)


Changeset truncated at 500 lines:

diff --git a/doc/socket_wrapper.1 b/doc/socket_wrapper.1
index a064eed..9f3f75a 100644
--- a/doc/socket_wrapper.1
+++ b/doc/socket_wrapper.1
@@ -44,7 +44,7 @@ socket_wrapper aims to help client/server software development teams willing to
 .sp -1
 .IP \(bu 2.3
 .\}
-Redirects all network communication to happen over unix sockets\&.
+Redirects all network communication to happen over Unix sockets\&.
 .RE
 .sp
 .RS 4
@@ -66,13 +66,13 @@ Support for IPv4 and IPv6 socket and addressing emulation\&.
 .sp -1
 .IP \(bu 2.3
 .\}
-Ablility to capture network traffic in pcap format\&.
+Ability to capture network traffic in pcap format\&.
 .RE
 .SH "ENVIRONMENT VARIABLES"
 .PP
 \fBSOCKET_WRAPPER_DIR\fR
 .RS 4
-The user defines a directory where to put all the unix sockets using the envionment variable "SOCKET_WRAPPER_DIR=/path/to/socket_dir"\&. When a server opens a port or a client wants to connect, socket_wrapper will translate IP addresses to a special socket_wrapper name and look for the relevant unix socket in the SOCKET_WRAPPER_DIR\&.
+The user defines a directory where to put all the unix sockets using the environment variable "SOCKET_WRAPPER_DIR=/path/to/socket_dir"\&. When a server opens a port or a client wants to connect, socket_wrapper will translate IP addresses to a special socket_wrapper name and look for the relevant Unix socket in the SOCKET_WRAPPER_DIR\&.
 .RE
 .PP
 \fBSOCKET_WRAPPER_DEFAULT_IFACE\fR
diff --git a/doc/socket_wrapper.1.txt b/doc/socket_wrapper.1.txt
index da16c6d..b3ba96c 100644
--- a/doc/socket_wrapper.1.txt
+++ b/doc/socket_wrapper.1.txt
@@ -21,9 +21,9 @@ gain full functional test coverage. It makes possible to run several instances
 of the full software stack on the same machine and perform locally functional
 testing of complex network configurations.
 
-- Redirects all network communication to happen over unix sockets.
+- Redirects all network communication to happen over Unix sockets.
 - Support for IPv4 and IPv6 socket and addressing emulation.
-- Ablility to capture network traffic in pcap format.
+- Ability to capture network traffic in pcap format.
 
 ENVIRONMENT VARIABLES
 ---------------------
@@ -31,9 +31,9 @@ ENVIRONMENT VARIABLES
 *SOCKET_WRAPPER_DIR*::
 
 The user defines a directory where to put all the unix sockets using the
-envionment variable "SOCKET_WRAPPER_DIR=/path/to/socket_dir". When a server
+environment variable "SOCKET_WRAPPER_DIR=/path/to/socket_dir". When a server
 opens a port or a client wants to connect, socket_wrapper will translate IP
-addresses to a special socket_wrapper name and look for the relevant unix
+addresses to a special socket_wrapper name and look for the relevant Unix
 socket in the SOCKET_WRAPPER_DIR.
 
 *SOCKET_WRAPPER_DEFAULT_IFACE*::
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index a5037f7..7841c85 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -2461,14 +2461,20 @@ static uint8_t *swrap_pcap_packet_init(struct timeval *tval,
 				       int unreachable,
 				       size_t *_packet_len)
 {
-	uint8_t *base;
-	uint8_t *buf;
-	struct swrap_packet_frame *frame;
-	union swrap_packet_ip *ip;
+	uint8_t *base = NULL;
+	uint8_t *buf = NULL;
+	union {
+		uint8_t *ptr;
+		struct swrap_packet_frame *frame;
+	} f;
+	union {
+		uint8_t *ptr;
+		union swrap_packet_ip *ip;
+	} i;
 	union swrap_packet_payload *pay;
 	size_t packet_len;
 	size_t alloc_len;
-	size_t nonwire_len = sizeof(*frame);
+	size_t nonwire_len = sizeof(struct swrap_packet_frame);
 	size_t wire_hdr_len = 0;
 	size_t wire_len = 0;
 	size_t ip_hdr_len = 0;
@@ -2490,7 +2496,7 @@ static uint8_t *swrap_pcap_packet_init(struct timeval *tval,
 		dest_in = (const struct sockaddr_in *)(const void *)dest;
 		src_port = src_in->sin_port;
 		dest_port = dest_in->sin_port;
-		ip_hdr_len = sizeof(ip->v4);
+		ip_hdr_len = sizeof(i.ip->v4);
 		break;
 #ifdef HAVE_IPV6
 	case AF_INET6:
@@ -2498,7 +2504,7 @@ static uint8_t *swrap_pcap_packet_init(struct timeval *tval,
 		dest_in6 = (const struct sockaddr_in6 *)(const void *)dest;
 		src_port = src_in6->sin6_port;
 		dest_port = dest_in6->sin6_port;
-		ip_hdr_len = sizeof(ip->v6);
+		ip_hdr_len = sizeof(i.ip->v6);
 		break;
 #endif
 	default:
@@ -2539,7 +2545,6 @@ static uint8_t *swrap_pcap_packet_init(struct timeval *tval,
 		if (wire_len > 64 ) {
 			icmp_truncate_len = wire_len - 64;
 		}
-		wire_hdr_len += icmp_hdr_len;
 		wire_len += icmp_hdr_len;
 	}
 
@@ -2555,39 +2560,50 @@ static uint8_t *swrap_pcap_packet_init(struct timeval *tval,
 	}
 
 	buf = base;
+	f.ptr = buf;
+
+	f.frame->seconds		= tval->tv_sec;
+	f.frame->micro_seconds	= tval->tv_usec;
+	f.frame->recorded_length	= wire_len - icmp_truncate_len;
+	f.frame->full_length	= wire_len - icmp_truncate_len;
 
-	frame = (struct swrap_packet_frame *)(void *)buf;
-	frame->seconds		= tval->tv_sec;
-	frame->micro_seconds	= tval->tv_usec;
-	frame->recorded_length	= wire_len - icmp_truncate_len;
-	frame->full_length	= wire_len - icmp_truncate_len;
 	buf += SWRAP_PACKET_FRAME_SIZE;
 
-	ip = (union swrap_packet_ip *)(void *)buf;
+	i.ptr = buf;
 	switch (src->sa_family) {
 	case AF_INET:
-		ip->v4.ver_hdrlen	= 0x45; /* version 4 and 5 * 32 bit words */
-		ip->v4.tos		= 0x00;
-		ip->v4.packet_length	= htons(wire_len - icmp_truncate_len);
-		ip->v4.identification	= htons(0xFFFF);
-		ip->v4.flags		= 0x40; /* BIT 1 set - means don't fragment */
-		ip->v4.fragment		= htons(0x0000);
-		ip->v4.ttl		= 0xFF;
-		ip->v4.protocol		= protocol;
-		ip->v4.hdr_checksum	= htons(0x0000);
-		ip->v4.src_addr		= src_in->sin_addr.s_addr;
-		ip->v4.dest_addr	= dest_in->sin_addr.s_addr;
+		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);
+		i.ip->v4.identification	= htons(0xFFFF);
+		i.ip->v4.flags		= 0x40; /* BIT 1 set - means don't fragment */
+		i.ip->v4.fragment	= htons(0x0000);
+		i.ip->v4.ttl		= 0xFF;
+		i.ip->v4.protocol	= protocol;
+		i.ip->v4.hdr_checksum	= htons(0x0000);
+		i.ip->v4.src_addr	= src_in->sin_addr.s_addr;
+		i.ip->v4.dest_addr	= dest_in->sin_addr.s_addr;
 		buf += SWRAP_PACKET_IP_V4_SIZE;
 		break;
 #ifdef HAVE_IPV6
 	case AF_INET6:
-		ip->v6.ver_prio		= 0x60; /* version 4 and 5 * 32 bit words */
-		ip->v6.flow_label_high	= 0x00;
-		ip->v6.flow_label_low	= 0x0000;
-		ip->v6.payload_length	= htons(wire_len - icmp_truncate_len); /* TODO */
-		ip->v6.next_header	= protocol;
-		memcpy(ip->v6.src_addr, src_in6->sin6_addr.s6_addr, 16);
-		memcpy(ip->v6.dest_addr, dest_in6->sin6_addr.s6_addr, 16);
+		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;
+		i.ip->v6.payload_length	= htons(wire_len - icmp_truncate_len); /* TODO */
+		i.ip->v6.next_header	= protocol;
+		memcpy(i.ip->v6.src_addr, src_in6->sin6_addr.s6_addr, 16);
+		memcpy(i.ip->v6.dest_addr, dest_in6->sin6_addr.s6_addr, 16);
 		buf += SWRAP_PACKET_IP_V6_SIZE;
 		break;
 #endif
@@ -2601,21 +2617,23 @@ static uint8_t *swrap_pcap_packet_init(struct timeval *tval,
 			pay->icmp4.code		= 0x01; /* host unreachable */
 			pay->icmp4.checksum	= htons(0x0000);
 			pay->icmp4.unused	= htonl(0x00000000);
+
 			buf += SWRAP_PACKET_PAYLOAD_ICMP4_SIZE;
 
 			/* set the ip header in the ICMP payload */
-			ip = (union swrap_packet_ip *)(void *)buf;
-			ip->v4.ver_hdrlen	= 0x45; /* version 4 and 5 * 32 bit words */
-			ip->v4.tos		= 0x00;
-			ip->v4.packet_length	= htons(wire_len - icmp_hdr_len);
-			ip->v4.identification	= htons(0xFFFF);
-			ip->v4.flags		= 0x40; /* BIT 1 set - means don't fragment */
-			ip->v4.fragment		= htons(0x0000);
-			ip->v4.ttl		= 0xFF;
-			ip->v4.protocol		= icmp_protocol;
-			ip->v4.hdr_checksum	= htons(0x0000);
-			ip->v4.src_addr		= dest_in->sin_addr.s_addr;
-			ip->v4.dest_addr	= src_in->sin_addr.s_addr;
+			i.ptr = buf;
+			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_hdr_len);
+			i.ip->v4.identification	= htons(0xFFFF);
+			i.ip->v4.flags		= 0x40; /* BIT 1 set - means don't fragment */
+			i.ip->v4.fragment	= htons(0x0000);
+			i.ip->v4.ttl		= 0xFF;
+			i.ip->v4.protocol	= icmp_protocol;
+			i.ip->v4.hdr_checksum	= htons(0x0000);
+			i.ip->v4.src_addr	= dest_in->sin_addr.s_addr;
+			i.ip->v4.dest_addr	= src_in->sin_addr.s_addr;
+
 			buf += SWRAP_PACKET_IP_V4_SIZE;
 
 			src_port = dest_in->sin_port;
@@ -2630,14 +2648,15 @@ static uint8_t *swrap_pcap_packet_init(struct timeval *tval,
 			buf += SWRAP_PACKET_PAYLOAD_ICMP6_SIZE;
 
 			/* set the ip header in the ICMP payload */
-			ip = (union swrap_packet_ip *)(void *)buf;
-			ip->v6.ver_prio		= 0x60; /* version 4 and 5 * 32 bit words */
-			ip->v6.flow_label_high	= 0x00;
-			ip->v6.flow_label_low	= 0x0000;
-			ip->v6.payload_length	= htons(wire_len - icmp_truncate_len); /* TODO */
-			ip->v6.next_header	= protocol;
-			memcpy(ip->v6.src_addr, dest_in6->sin6_addr.s6_addr, 16);
-			memcpy(ip->v6.dest_addr, src_in6->sin6_addr.s6_addr, 16);
+			i.ptr = buf;
+			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;
+			i.ip->v6.payload_length	= htons(wire_len - icmp_truncate_len); /* TODO */
+			i.ip->v6.next_header	= protocol;
+			memcpy(i.ip->v6.src_addr, dest_in6->sin6_addr.s6_addr, 16);
+			memcpy(i.ip->v6.dest_addr, src_in6->sin6_addr.s6_addr, 16);
+
 			buf += SWRAP_PACKET_IP_V6_SIZE;
 
 			src_port = dest_in6->sin6_port;
diff --git a/tests/echo_srv.c b/tests/echo_srv.c
index fac4e8e..01e3325 100644
--- a/tests/echo_srv.c
+++ b/tests/echo_srv.c
@@ -886,7 +886,7 @@ int main(int argc, char **argv)
                                 "[-D] [--pid pidfile]\n"
                                 "-t makes the server listen on TCP\n"
                                 "-u makes the server listen on UDP\n"
-                                "-D tells the server to become a deamon and " \
+                                "-D tells the server to become a daemon and " \
                                 "write a PIDfile\n"
                                 "The default port is 7, the default PIDfile is " \
                                 "echo_srv.pid in the current directory\n",


-- 
Socket Wrapper Repository



More information about the samba-cvs mailing list