diff options
author | Matt Johnston <matt@ucc.asn.au> | 2017-05-12 23:14:54 +0800 |
---|---|---|
committer | Matt Johnston <matt@ucc.asn.au> | 2017-05-12 23:14:54 +0800 |
commit | 9f24cdf74c93aa75416687972e69b5b4c8be2698 (patch) | |
tree | 9de10a9cfb200ced849cce21005253e0b93b7711 /packet.c | |
parent | d7471c4f875a2be9dde4e65d06f71bf7c68d5ff5 (diff) |
copy over some fuzzing code from AFL branch
--HG--
branch : fuzz
Diffstat (limited to 'packet.c')
-rw-r--r-- | packet.c | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -35,6 +35,7 @@ #include "auth.h" #include "channel.h" #include "netio.h" +#include "runopts.h" static int read_packet_init(void); static void make_mac(unsigned int seqno, const struct key_context_directional * key_state, @@ -76,6 +77,15 @@ 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 (opts.fuzz.fuzzing) { + // pretend to write one packet at a time + // TODO(fuzz): randomise amount written based on the fuzz input + written = iov[0].iov_len; + } + else +#endif + { written = writev(ses.sock_out, iov, iov_count); if (written < 0) { if (errno == EINTR || errno == EAGAIN) { @@ -85,6 +95,7 @@ void write_packet() { dropbear_exit("Error writing: %s", strerror(errno)); } } + } packet_queue_consume(&ses.writequeue, written); ses.writequeue_len -= written; @@ -94,6 +105,9 @@ void write_packet() { } #else /* No writev () */ +#ifdef 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*/ writebuf = (buffer*)examine(&ses.writequeue); |