diff options
author | Matt Johnston <matt@ucc.asn.au> | 2013-03-20 23:13:19 +0800 |
---|---|---|
committer | Matt Johnston <matt@ucc.asn.au> | 2013-03-20 23:13:19 +0800 |
commit | 34f9b2a8f7fa284f7d23cdd54cf3f3a2964200d0 (patch) | |
tree | 078eef5d7bca66115d0c85b2b2328eec601f6c62 /packet.c | |
parent | d37dcc636f6d7832b969aa94d2446894cd44a680 (diff) |
Fix "-m none" case where an entire packet fits in a block and can be
read by read_packet_init()
Diffstat (limited to 'packet.c')
-rw-r--r-- | packet.c | 31 |
1 files changed, 19 insertions, 12 deletions
@@ -133,22 +133,29 @@ void read_packet() { /* Attempt to read the remainder of the packet, note that there * mightn't be any available (EAGAIN) */ maxlen = ses.readbuf->len - ses.readbuf->pos; - len = read(ses.sock_in, buf_getptr(ses.readbuf, maxlen), maxlen); + if (maxlen == 0) { + /* Occurs when the packet is only a single block long and has all + * been read in read_packet_init(). Usually means that MAC is disabled + */ + len = 0; + } else { + len = read(ses.sock_in, buf_getptr(ses.readbuf, maxlen), maxlen); - if (len == 0) { - ses.remoteclosed(); - } + if (len == 0) { + ses.remoteclosed(); + } - if (len < 0) { - if (errno == EINTR || errno == EAGAIN) { - TRACE(("leave read_packet: EINTR or EAGAIN")) - return; - } else { - dropbear_exit("Error reading: %s", strerror(errno)); + if (len < 0) { + if (errno == EINTR || errno == EAGAIN) { + TRACE(("leave read_packet: EINTR or EAGAIN")) + return; + } else { + dropbear_exit("Error reading: %s", strerror(errno)); + } } - } - buf_incrpos(ses.readbuf, len); + buf_incrpos(ses.readbuf, len); + } if ((unsigned int)len == maxlen) { /* The whole packet has been read */ |