- #if not #ifdef for DROPBEAR_FUZZ

- fix some unused variables

--HG--
branch : fuzz
This commit is contained in:
Matt Johnston 2018-02-28 21:40:08 +08:00
parent 9bbce01e1b
commit c658b275fd
14 changed files with 30 additions and 29 deletions

View File

@ -949,7 +949,7 @@ static void read_kex_algos() {
ses.newkeys->trans.algo_comp = s2c_comp_algo->val; ses.newkeys->trans.algo_comp = s2c_comp_algo->val;
} }
#ifdef DROPBEAR_FUZZ #if DROPBEAR_FUZZ
if (fuzz.fuzzing) { if (fuzz.fuzzing) {
fuzz_kex_fakealgos(); fuzz_kex_fakealgos();
} }

View File

@ -75,7 +75,7 @@ void common_session_init(int sock_in, int sock_out) {
ses.last_packet_time_any_sent = 0; ses.last_packet_time_any_sent = 0;
ses.last_packet_time_keepalive_sent = 0; ses.last_packet_time_keepalive_sent = 0;
#ifdef DROPBEAR_FUZZ #if DROPBEAR_FUZZ
if (!fuzz.fuzzing) if (!fuzz.fuzzing)
#endif #endif
{ {
@ -158,7 +158,7 @@ void session_loop(void(*loophandler)(void)) {
/* We get woken up when signal handlers write to this pipe. /* We get woken up when signal handlers write to this pipe.
SIGCHLD in svr-chansession is the only one currently. */ SIGCHLD in svr-chansession is the only one currently. */
#ifdef DROPBEAR_FUZZ #if DROPBEAR_FUZZ
if (!fuzz.fuzzing) if (!fuzz.fuzzing)
#endif #endif
{ {

View File

@ -12,7 +12,7 @@ AC_CONFIG_SRCDIR(buffer.c)
# Record which revision is being built # Record which revision is being built
if which -s hg && test -d "$srcdir/.hg"; then if which -s hg && test -d "$srcdir/.hg"; then
hgrev=`hg id -i -R "$srcdir"` hgrev=`hg id -i -R "$srcdir"`
echo "Source directory Mercurial base revision $hgrev" AC_MSG_NOTICE([Source directory Mercurial base revision $hgrev])
fi fi
# Checks for programs. # Checks for programs.
@ -330,6 +330,7 @@ AC_ARG_ENABLE(fuzz,
DROPBEAR_FUZZ=1 DROPBEAR_FUZZ=1
], ],
[ [
AC_DEFINE(DROPBEAR_FUZZ, 0, Fuzzing)
DROPBEAR_FUZZ=0 DROPBEAR_FUZZ=0
] ]

View File

@ -145,7 +145,7 @@ void addrandom(const unsigned char * buf, unsigned int len)
{ {
hash_state hs; hash_state hs;
#ifdef DROPBEAR_FUZZ #if DROPBEAR_FUZZ
if (fuzz.fuzzing || fuzz.recordf) { if (fuzz.fuzzing || fuzz.recordf) {
return; return;
} }
@ -163,7 +163,7 @@ void addrandom(const unsigned char * buf, unsigned int len)
static void write_urandom() static void write_urandom()
{ {
#ifdef DROPBEAR_FUZZ #if DROPBEAR_FUZZ
if (fuzz.fuzzing || fuzz.recordf) { if (fuzz.fuzzing || fuzz.recordf) {
return; return;
} }
@ -181,7 +181,7 @@ static void write_urandom()
#endif #endif
} }
#ifdef DROPBEAR_FUZZ #if DROPBEAR_FUZZ
void fuzz_seed(void) { void fuzz_seed(void) {
hash_state hs; hash_state hs;
sha1_init(&hs); sha1_init(&hs);
@ -203,7 +203,7 @@ void seedrandom() {
struct timeval tv; struct timeval tv;
clock_t clockval; clock_t clockval;
#ifdef DROPBEAR_FUZZ #if DROPBEAR_FUZZ
if (fuzz.fuzzing || fuzz.recordf) { if (fuzz.fuzzing || fuzz.recordf) {
return; return;
} }

View File

@ -120,7 +120,7 @@ static void generic_dropbear_exit(int exitcode, const char* format,
_dropbear_log(LOG_INFO, fmtbuf, param); _dropbear_log(LOG_INFO, fmtbuf, param);
#ifdef DROPBEAR_FUZZ #if DROPBEAR_FUZZ
// longjmp before cleaning up svr_opts // longjmp before cleaning up svr_opts
if (fuzz.do_jmp) { if (fuzz.do_jmp) {
longjmp(fuzz.jmp, 1); longjmp(fuzz.jmp, 1);
@ -532,7 +532,7 @@ void setnonblocking(int fd) {
TRACE(("setnonblocking: %d", fd)) TRACE(("setnonblocking: %d", fd))
#ifdef DROPBEAR_FUZZ #if DROPBEAR_FUZZ
if (fuzz.fuzzing) { if (fuzz.fuzzing) {
return; return;
} }
@ -629,7 +629,7 @@ static clockid_t get_linux_clock_source() {
#endif #endif
time_t monotonic_now() { time_t monotonic_now() {
#ifdef DROPBEAR_FUZZ #if DROPBEAR_FUZZ
if (fuzz.fuzzing) { if (fuzz.fuzzing) {
/* time stands still when fuzzing */ /* time stands still when fuzzing */
return 5; return 5;

View File

@ -42,21 +42,21 @@ int fuzz_set_input(const uint8_t *Data, size_t Size) {
return DROPBEAR_SUCCESS; return DROPBEAR_SUCCESS;
} }
static void fuzz_dropbear_log(int UNUSED(priority), const char* format, va_list param) {
char printbuf[1024];
#if DEBUG_TRACE #if DEBUG_TRACE
static void fuzz_dropbear_log(int UNUSED(priority), const char* format, va_list param) {
if (debug_trace) { if (debug_trace) {
char printbuf[1024];
vsnprintf(printbuf, sizeof(printbuf), format, param); vsnprintf(printbuf, sizeof(printbuf), format, param);
fprintf(stderr, "%s\n", printbuf); 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) { void fuzz_svr_setup(void) {
struct passwd *pw;
fuzz_common_setup(); fuzz_common_setup();
_dropbear_exit = svr_dropbear_exit; _dropbear_exit = svr_dropbear_exit;

2
fuzz.h
View File

@ -2,7 +2,7 @@
#define DROPBEAR_FUZZ_H #define DROPBEAR_FUZZ_H
#include "config.h" #include "config.h"
#ifdef DROPBEAR_FUZZ #if DROPBEAR_FUZZ
#include "includes.h" #include "includes.h"
#include "buffer.h" #include "buffer.h"

View File

@ -361,7 +361,7 @@ void set_sock_priority(int sock, enum dropbear_prio prio) {
int so_prio_val = 0; int so_prio_val = 0;
#endif #endif
#ifdef DROPBEAR_FUZZ #if DROPBEAR_FUZZ
if (fuzz.fuzzing) { if (fuzz.fuzzing) {
TRACE(("fuzzing skips set_sock_prio")) TRACE(("fuzzing skips set_sock_prio"))
return; return;

View File

@ -77,7 +77,7 @@ void write_packet() {
/* This may return EAGAIN. The main loop sometimes /* This may return EAGAIN. The main loop sometimes
calls write_packet() without bothering to test with select() since calls write_packet() without bothering to test with select() since
it's likely to be necessary */ it's likely to be necessary */
#ifdef DROPBEAR_FUZZ #if DROPBEAR_FUZZ
if (fuzz.fuzzing) { if (fuzz.fuzzing) {
// pretend to write one packet at a time // pretend to write one packet at a time
// TODO(fuzz): randomise amount written based on the fuzz input // TODO(fuzz): randomise amount written based on the fuzz input
@ -105,7 +105,7 @@ void write_packet() {
} }
#else /* No writev () */ #else /* No writev () */
#ifdef DROPBEAR_FUZZ #if DROPBEAR_FUZZ
_Static_assert(0, "No fuzzing code for no-writev writes"); _Static_assert(0, "No fuzzing code for no-writev writes");
#endif #endif
/* Get the next buffer in the queue of encrypted packets to write*/ /* Get the next buffer in the queue of encrypted packets to write*/
@ -366,7 +366,7 @@ static int checkmac() {
buf_setpos(ses.readbuf, 0); buf_setpos(ses.readbuf, 0);
make_mac(ses.recvseq, &ses.keys->recv, ses.readbuf, contents_len, mac_bytes); make_mac(ses.recvseq, &ses.keys->recv, ses.readbuf, contents_len, mac_bytes);
#ifdef DROPBEAR_FUZZ #if DROPBEAR_FUZZ
if (fuzz.fuzzing) { if (fuzz.fuzzing) {
// fail 1 in 2000 times to test error path. // fail 1 in 2000 times to test error path.
// note that mac_bytes is all zero prior to kex, so don't test ==0 ! // note that mac_bytes is all zero prior to kex, so don't test ==0 !

View File

@ -628,7 +628,7 @@ out:
} }
#endif #endif
#ifdef DROPBEAR_FUZZ #if DROPBEAR_FUZZ
const char * const * fuzz_signkey_names = signkey_names; const char * const * fuzz_signkey_names = signkey_names;
#endif #endif

View File

@ -312,7 +312,7 @@ static int checkusername(const char *username, unsigned int userlen) {
return DROPBEAR_FAILURE; return DROPBEAR_FAILURE;
} }
} }
#endif HAVE_GETGROUPLIST #endif
TRACE(("shell is %s", ses.authstate.pw_shell)) TRACE(("shell is %s", ses.authstate.pw_shell))
@ -395,7 +395,7 @@ void send_msg_userauth_failure(int partial, int incrfail) {
genrandom((unsigned char*)&delay, sizeof(delay)); genrandom((unsigned char*)&delay, sizeof(delay));
/* We delay for 300ms +- 50ms */ /* We delay for 300ms +- 50ms */
delay = 250000 + (delay % 100000); delay = 250000 + (delay % 100000);
#ifdef DROPBEAR_FUZZ #if DROPBEAR_FUZZ
if (!fuzz.fuzzing) { if (!fuzz.fuzzing) {
usleep(delay); usleep(delay);
} }

View File

@ -473,7 +473,7 @@ static int checkfileperm(char * filename) {
return DROPBEAR_SUCCESS; return DROPBEAR_SUCCESS;
} }
#ifdef DROPBEAR_FUZZ #if DROPBEAR_FUZZ
int fuzz_checkpubkey_line(buffer* line, int line_num, char* filename, int fuzz_checkpubkey_line(buffer* line, int line_num, char* filename,
const char* algo, unsigned int algolen, const char* algo, unsigned int algolen,
const unsigned char* keyblob, unsigned int keybloblen) { const unsigned char* keyblob, unsigned int keybloblen) {

View File

@ -179,7 +179,7 @@ static void send_msg_kexdh_reply(mp_int *dh_e, buffer *ecdh_qs) {
} }
#endif #endif
#ifdef DROPBEAR_FUZZ #if DROPBEAR_FUZZ
if (fuzz.fuzzing && fuzz.skip_kexmaths) { if (fuzz.fuzzing && fuzz.skip_kexmaths) {
fuzz_fake_send_kexdh_reply(); fuzz_fake_send_kexdh_reply();
return; return;

View File

@ -185,7 +185,7 @@ void svr_dropbear_exit(int exitcode, const char* format, va_list param) {
session_cleanup(); session_cleanup();
} }
#ifdef DROPBEAR_FUZZ #if DROPBEAR_FUZZ
// longjmp before cleaning up svr_opts // longjmp before cleaning up svr_opts
if (fuzz.do_jmp) { if (fuzz.do_jmp) {
longjmp(fuzz.jmp, 1); longjmp(fuzz.jmp, 1);