changeset 1558:2f64cb3d3007 fuzz

- #if not #ifdef for DROPBEAR_FUZZ - fix some unused variables
author Matt Johnston <matt@ucc.asn.au>
date Wed, 28 Feb 2018 21:40:08 +0800
parents 61a793b6e471
children 92c93b4a3646
files common-kex.c common-session.c configure.ac dbrandom.c dbutil.c fuzz-common.c fuzz.h netio.c packet.c signkey.c svr-auth.c svr-authpubkey.c svr-kex.c svr-session.c
diffstat 14 files changed, 30 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/common-kex.c	Wed Feb 28 21:28:59 2018 +0800
+++ b/common-kex.c	Wed Feb 28 21:40:08 2018 +0800
@@ -949,7 +949,7 @@
 		ses.newkeys->trans.algo_comp = s2c_comp_algo->val;
 	}
 
-#ifdef DROPBEAR_FUZZ
+#if DROPBEAR_FUZZ
 	if (fuzz.fuzzing) {
 		fuzz_kex_fakealgos();
 	}
--- a/common-session.c	Wed Feb 28 21:28:59 2018 +0800
+++ b/common-session.c	Wed Feb 28 21:40:08 2018 +0800
@@ -75,7 +75,7 @@
 	ses.last_packet_time_any_sent = 0;
 	ses.last_packet_time_keepalive_sent = 0;
 	
-#ifdef DROPBEAR_FUZZ
+#if DROPBEAR_FUZZ
 	if (!fuzz.fuzzing)
 #endif
 	{
@@ -158,7 +158,7 @@
 
 		/* We get woken up when signal handlers write to this pipe.
 		   SIGCHLD in svr-chansession is the only one currently. */
-#ifdef DROPBEAR_FUZZ
+#if DROPBEAR_FUZZ
 		if (!fuzz.fuzzing) 
 #endif
 		{
--- a/configure.ac	Wed Feb 28 21:28:59 2018 +0800
+++ b/configure.ac	Wed Feb 28 21:40:08 2018 +0800
@@ -12,7 +12,7 @@
 # Record which revision is being built
 if which -s hg && test -d "$srcdir/.hg"; then
 	hgrev=`hg id -i -R "$srcdir"`
-	echo "Source directory Mercurial base revision $hgrev"
+	AC_MSG_NOTICE([Source directory Mercurial base revision $hgrev])
 fi
 
 # Checks for programs.
@@ -330,6 +330,7 @@
 		DROPBEAR_FUZZ=1
 	],
 	[
+		AC_DEFINE(DROPBEAR_FUZZ, 0, Fuzzing)
 		DROPBEAR_FUZZ=0
 	]
 
--- a/dbrandom.c	Wed Feb 28 21:28:59 2018 +0800
+++ b/dbrandom.c	Wed Feb 28 21:40:08 2018 +0800
@@ -145,7 +145,7 @@
 {
 	hash_state hs;
 
-#ifdef DROPBEAR_FUZZ
+#if DROPBEAR_FUZZ
 	if (fuzz.fuzzing || fuzz.recordf) {
 		return;
 	}
@@ -163,7 +163,7 @@
 
 static void write_urandom()
 {
-#ifdef DROPBEAR_FUZZ
+#if DROPBEAR_FUZZ
 	if (fuzz.fuzzing || fuzz.recordf) {
 		return;
 	}
@@ -181,7 +181,7 @@
 #endif
 }
 
-#ifdef DROPBEAR_FUZZ
+#if DROPBEAR_FUZZ
 void fuzz_seed(void) {
 	hash_state hs;
 	sha1_init(&hs);
@@ -203,7 +203,7 @@
 	struct timeval tv;
 	clock_t clockval;
 
-#ifdef DROPBEAR_FUZZ
+#if DROPBEAR_FUZZ
 	if (fuzz.fuzzing || fuzz.recordf) {
 		return;
 	}
--- a/dbutil.c	Wed Feb 28 21:28:59 2018 +0800
+++ b/dbutil.c	Wed Feb 28 21:40:08 2018 +0800
@@ -120,7 +120,7 @@
 
 	_dropbear_log(LOG_INFO, fmtbuf, param);
 
-#ifdef DROPBEAR_FUZZ
+#if DROPBEAR_FUZZ
 	// longjmp before cleaning up svr_opts
     if (fuzz.do_jmp) {
         longjmp(fuzz.jmp, 1);
@@ -532,7 +532,7 @@
 
 	TRACE(("setnonblocking: %d", fd))
 
-#ifdef DROPBEAR_FUZZ
+#if DROPBEAR_FUZZ
 	if (fuzz.fuzzing) {
 		return;
 	}
@@ -629,7 +629,7 @@
 #endif 
 
 time_t monotonic_now() {
-#ifdef DROPBEAR_FUZZ
+#if DROPBEAR_FUZZ
 	if (fuzz.fuzzing) {
 		/* time stands still when fuzzing */
 		return 5;
--- a/fuzz-common.c	Wed Feb 28 21:28:59 2018 +0800
+++ b/fuzz-common.c	Wed Feb 28 21:40:08 2018 +0800
@@ -42,21 +42,21 @@
     return DROPBEAR_SUCCESS;
 }
 
+#if DEBUG_TRACE
 static void fuzz_dropbear_log(int UNUSED(priority), const char* format, va_list param) {
-
-    char printbuf[1024];
-
-#if DEBUG_TRACE
     if (debug_trace) {
+        char printbuf[1024];
         vsnprintf(printbuf, sizeof(printbuf), format, param);
         fprintf(stderr, "%s\n", printbuf);
     }
-#endif
 }
+#else
+static void fuzz_dropbear_log(int UNUSED(priority), const char* UNUSED(format), va_list UNUSED(param)) {
+    /* No print */
+}
+#endif /* DEBUG_TRACE */
 
 void fuzz_svr_setup(void) {
-    struct passwd *pw;
-
     fuzz_common_setup();
     
     _dropbear_exit = svr_dropbear_exit;
--- a/fuzz.h	Wed Feb 28 21:28:59 2018 +0800
+++ b/fuzz.h	Wed Feb 28 21:40:08 2018 +0800
@@ -2,7 +2,7 @@
 #define DROPBEAR_FUZZ_H
 
 #include "config.h"
-#ifdef DROPBEAR_FUZZ
+#if DROPBEAR_FUZZ
 
 #include "includes.h"
 #include "buffer.h"
--- a/netio.c	Wed Feb 28 21:28:59 2018 +0800
+++ b/netio.c	Wed Feb 28 21:40:08 2018 +0800
@@ -361,7 +361,7 @@
 	int so_prio_val = 0;
 #endif
 
-#ifdef DROPBEAR_FUZZ
+#if DROPBEAR_FUZZ
 	if (fuzz.fuzzing) {
 		TRACE(("fuzzing skips set_sock_prio"))
 		return;
--- a/packet.c	Wed Feb 28 21:28:59 2018 +0800
+++ b/packet.c	Wed Feb 28 21:40:08 2018 +0800
@@ -77,7 +77,7 @@
 	/* This may return EAGAIN. The main loop sometimes
 	calls write_packet() without bothering to test with select() since
 	it's likely to be necessary */
-#ifdef DROPBEAR_FUZZ
+#if DROPBEAR_FUZZ
 	if (fuzz.fuzzing) {
 		// pretend to write one packet at a time
 		// TODO(fuzz): randomise amount written based on the fuzz input
@@ -105,7 +105,7 @@
 	}
 
 #else /* No writev () */
-#ifdef DROPBEAR_FUZZ
+#if DROPBEAR_FUZZ
 	_Static_assert(0, "No fuzzing code for no-writev writes");
 #endif
 	/* Get the next buffer in the queue of encrypted packets to write*/
@@ -366,7 +366,7 @@
 	buf_setpos(ses.readbuf, 0);
 	make_mac(ses.recvseq, &ses.keys->recv, ses.readbuf, contents_len, mac_bytes);
 
-#ifdef DROPBEAR_FUZZ
+#if DROPBEAR_FUZZ
 	if (fuzz.fuzzing) {
 		// fail 1 in 2000 times to test error path.
 		// note that mac_bytes is all zero prior to kex, so don't test ==0 !
--- a/signkey.c	Wed Feb 28 21:28:59 2018 +0800
+++ b/signkey.c	Wed Feb 28 21:40:08 2018 +0800
@@ -628,7 +628,7 @@
 }
 #endif
 
-#ifdef DROPBEAR_FUZZ
+#if DROPBEAR_FUZZ
 const char * const * fuzz_signkey_names = signkey_names;
 
 #endif
--- a/svr-auth.c	Wed Feb 28 21:28:59 2018 +0800
+++ b/svr-auth.c	Wed Feb 28 21:40:08 2018 +0800
@@ -312,7 +312,7 @@
 			return DROPBEAR_FAILURE;
 		}
 	}
-#endif HAVE_GETGROUPLIST
+#endif
 
 	TRACE(("shell is %s", ses.authstate.pw_shell))
 
@@ -395,7 +395,7 @@
 		genrandom((unsigned char*)&delay, sizeof(delay));
 		/* We delay for 300ms +- 50ms */
 		delay = 250000 + (delay % 100000);
-#ifdef DROPBEAR_FUZZ
+#if DROPBEAR_FUZZ
 		if (!fuzz.fuzzing) {
 			usleep(delay);
 		}
--- a/svr-authpubkey.c	Wed Feb 28 21:28:59 2018 +0800
+++ b/svr-authpubkey.c	Wed Feb 28 21:40:08 2018 +0800
@@ -473,7 +473,7 @@
 	return DROPBEAR_SUCCESS;
 }
 
-#ifdef DROPBEAR_FUZZ
+#if DROPBEAR_FUZZ
 int fuzz_checkpubkey_line(buffer* line, int line_num, char* filename,
 		const char* algo, unsigned int algolen,
 		const unsigned char* keyblob, unsigned int keybloblen) {
--- a/svr-kex.c	Wed Feb 28 21:28:59 2018 +0800
+++ b/svr-kex.c	Wed Feb 28 21:40:08 2018 +0800
@@ -179,7 +179,7 @@
 	}
 #endif
 
-#ifdef DROPBEAR_FUZZ
+#if DROPBEAR_FUZZ
 	if (fuzz.fuzzing && fuzz.skip_kexmaths) {
 		fuzz_fake_send_kexdh_reply();
 		return;
--- a/svr-session.c	Wed Feb 28 21:28:59 2018 +0800
+++ b/svr-session.c	Wed Feb 28 21:40:08 2018 +0800
@@ -185,7 +185,7 @@
 		session_cleanup();
 	}
 
-#ifdef DROPBEAR_FUZZ
+#if DROPBEAR_FUZZ
 	// longjmp before cleaning up svr_opts
     if (fuzz.do_jmp) {
         longjmp(fuzz.jmp, 1);