diff netio.c @ 1383:f03cfe9c76ac fuzz

Disable setnonblocking(), get_socket_address(), set_sock_priority() for fuzzing
author Matt Johnston <matt@ucc.asn.au>
date Fri, 26 May 2017 22:10:51 +0800
parents 08f4fa4dc6a0
children 69862e8cc405
line wrap: on
line diff
--- a/netio.c	Fri May 26 22:09:30 2017 +0800
+++ b/netio.c	Fri May 26 22:10:51 2017 +0800
@@ -311,6 +311,12 @@
 	int so_prio_val = 0;
 #endif
 
+#ifdef DROPBEAR_FUZZ
+	if (fuzz.fuzzing) {
+		TRACE(("fuzzing skips set_sock_prio"))
+		return;
+	}
+#endif
 
 	/* Don't log ENOTSOCK errors so that this can harmlessly be called
 	 * on a client '-J' proxy pipe */
@@ -482,40 +488,25 @@
 {
 	struct sockaddr_storage addr;
 	socklen_t addrlen;
+
+#if DROPBEAR_FUZZ
+	if (fuzz.fuzzing) {
+		fuzz_get_socket_address(fd, local_host, local_port, remote_host, remote_port, host_lookup);
+		return;
+	}
+#endif
 	
 	if (local_host || local_port) {
 		addrlen = sizeof(addr);
 		if (getsockname(fd, (struct sockaddr*)&addr, &addrlen) < 0) {
-			if (errno == ENOTSOCK) {
-				// FUZZ
-				if (local_host) {
-					*local_host = m_strdup("notsocket");
-				}
-				if (local_port) {
-					*local_port = m_strdup("999");
-				}
-				return;
-			} else {
-				dropbear_exit("Failed socket address: %s", strerror(errno));
-			}
+			dropbear_exit("Failed socket address: %s", strerror(errno));
 		}
 		getaddrstring(&addr, local_host, local_port, host_lookup);		
 	}
 	if (remote_host || remote_port) {
 		addrlen = sizeof(addr);
 		if (getpeername(fd, (struct sockaddr*)&addr, &addrlen) < 0) {
-			if (errno == ENOTSOCK) {
-				// FUZZ
-				if (remote_host) {
-					*remote_host = m_strdup("notsocket");
-				}
-				if (remote_port) {
-					*remote_port = m_strdup("999");
-				}
-				return;
-			} else {
-				dropbear_exit("Failed socket address: %s", strerror(errno));
-			}
+			dropbear_exit("Failed socket address: %s", strerror(errno));
 		}
 		getaddrstring(&addr, remote_host, remote_port, host_lookup);		
 	}
@@ -569,18 +560,6 @@
 			return;
 		} else {
 			/* if we can't do a numeric lookup, something's gone terribly wrong */
-			if (ret == EAI_FAMILY) {
-				// FUZZ
-				// Fake it for non-socket input
-				if (ret_host) {
-					*ret_host = m_strdup("0.0.0.0");
-				}
-				if (ret_port)
-				{
-					*ret_port = m_strdup("999");
-				}
-				return;
-			}
 			dropbear_exit("Failed lookup: %s", gai_strerror(ret));
 		}
 	}