Skip to content

Commit

Permalink
- #if not #ifdef for DROPBEAR_FUZZ
Browse files Browse the repository at this point in the history
- fix some unused variables

--HG--
branch : fuzz
  • Loading branch information
mkj committed Feb 28, 2018
1 parent 9bbce01 commit c658b27
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 29 deletions.
2 changes: 1 addition & 1 deletion common-kex.c
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ static void read_kex_algos() {
ses.newkeys->trans.algo_comp = s2c_comp_algo->val;
}

#ifdef DROPBEAR_FUZZ
#if DROPBEAR_FUZZ
if (fuzz.fuzzing) {
fuzz_kex_fakealgos();
}
Expand Down
4 changes: 2 additions & 2 deletions common-session.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_keepalive_sent = 0;

#ifdef DROPBEAR_FUZZ
#if DROPBEAR_FUZZ
if (!fuzz.fuzzing)
#endif
{
Expand Down Expand Up @@ -158,7 +158,7 @@ void session_loop(void(*loophandler)(void)) {

/* 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
{
Expand Down
3 changes: 2 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ AC_CONFIG_SRCDIR(buffer.c)
# 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.
Expand Down Expand Up @@ -330,6 +330,7 @@ AC_ARG_ENABLE(fuzz,
DROPBEAR_FUZZ=1
],
[
AC_DEFINE(DROPBEAR_FUZZ, 0, Fuzzing)
DROPBEAR_FUZZ=0
]

Expand Down
8 changes: 4 additions & 4 deletions dbrandom.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void addrandom(const unsigned char * buf, unsigned int len)
{
hash_state hs;

#ifdef DROPBEAR_FUZZ
#if DROPBEAR_FUZZ
if (fuzz.fuzzing || fuzz.recordf) {
return;
}
Expand All @@ -163,7 +163,7 @@ void addrandom(const unsigned char * buf, unsigned int len)

static void write_urandom()
{
#ifdef DROPBEAR_FUZZ
#if DROPBEAR_FUZZ
if (fuzz.fuzzing || fuzz.recordf) {
return;
}
Expand All @@ -181,7 +181,7 @@ static void write_urandom()
#endif
}

#ifdef DROPBEAR_FUZZ
#if DROPBEAR_FUZZ
void fuzz_seed(void) {
hash_state hs;
sha1_init(&hs);
Expand All @@ -203,7 +203,7 @@ void seedrandom() {
struct timeval tv;
clock_t clockval;

#ifdef DROPBEAR_FUZZ
#if DROPBEAR_FUZZ
if (fuzz.fuzzing || fuzz.recordf) {
return;
}
Expand Down
6 changes: 3 additions & 3 deletions dbutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ static void generic_dropbear_exit(int exitcode, const char* format,

_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);
Expand Down Expand Up @@ -532,7 +532,7 @@ void setnonblocking(int fd) {

TRACE(("setnonblocking: %d", fd))

#ifdef DROPBEAR_FUZZ
#if DROPBEAR_FUZZ
if (fuzz.fuzzing) {
return;
}
Expand Down Expand Up @@ -629,7 +629,7 @@ static clockid_t get_linux_clock_source() {
#endif

time_t monotonic_now() {
#ifdef DROPBEAR_FUZZ
#if DROPBEAR_FUZZ
if (fuzz.fuzzing) {
/* time stands still when fuzzing */
return 5;
Expand Down
14 changes: 7 additions & 7 deletions fuzz-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ int fuzz_set_input(const uint8_t *Data, size_t Size) {
return DROPBEAR_SUCCESS;
}

static void fuzz_dropbear_log(int UNUSED(priority), const char* format, va_list param) {

char printbuf[1024];

#if DEBUG_TRACE
static void fuzz_dropbear_log(int UNUSED(priority), const char* format, va_list param) {
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;
Expand Down
2 changes: 1 addition & 1 deletion fuzz.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define DROPBEAR_FUZZ_H

#include "config.h"
#ifdef DROPBEAR_FUZZ
#if DROPBEAR_FUZZ

#include "includes.h"
#include "buffer.h"
Expand Down
2 changes: 1 addition & 1 deletion netio.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ void set_sock_priority(int sock, enum dropbear_prio prio) {
int so_prio_val = 0;
#endif

#ifdef DROPBEAR_FUZZ
#if DROPBEAR_FUZZ
if (fuzz.fuzzing) {
TRACE(("fuzzing skips set_sock_prio"))
return;
Expand Down
6 changes: 3 additions & 3 deletions packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void write_packet() {
/* 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
Expand Down Expand Up @@ -105,7 +105,7 @@ void write_packet() {
}

#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*/
Expand Down Expand Up @@ -366,7 +366,7 @@ static int checkmac() {
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 !
Expand Down
2 changes: 1 addition & 1 deletion signkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ int cmp_base64_key(const unsigned char* keyblob, unsigned int keybloblen,
}
#endif

#ifdef DROPBEAR_FUZZ
#if DROPBEAR_FUZZ
const char * const * fuzz_signkey_names = signkey_names;

#endif
4 changes: 2 additions & 2 deletions svr-auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ static int checkusername(const char *username, unsigned int userlen) {
return DROPBEAR_FAILURE;
}
}
#endif HAVE_GETGROUPLIST
#endif

TRACE(("shell is %s", ses.authstate.pw_shell))

Expand Down Expand Up @@ -395,7 +395,7 @@ void send_msg_userauth_failure(int partial, int incrfail) {
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);
}
Expand Down
2 changes: 1 addition & 1 deletion svr-authpubkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ static int checkfileperm(char * filename) {
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) {
Expand Down
2 changes: 1 addition & 1 deletion svr-kex.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ static void send_msg_kexdh_reply(mp_int *dh_e, buffer *ecdh_qs) {
}
#endif

#ifdef DROPBEAR_FUZZ
#if DROPBEAR_FUZZ
if (fuzz.fuzzing && fuzz.skip_kexmaths) {
fuzz_fake_send_kexdh_reply();
return;
Expand Down
2 changes: 1 addition & 1 deletion svr-session.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ void svr_dropbear_exit(int exitcode, const char* format, va_list param) {
session_cleanup();
}

#ifdef DROPBEAR_FUZZ
#if DROPBEAR_FUZZ
// longjmp before cleaning up svr_opts
if (fuzz.do_jmp) {
longjmp(fuzz.jmp, 1);
Expand Down

0 comments on commit c658b27

Please sign in to comment.