# HG changeset patch # User Matt Johnston # Date 1363792399 -28800 # Node ID f4232b65b316ffbc2028479e42a96fdebb26f07e # Parent 91dd8328a3ffe7933dd35b602276e5a12bf59306 Fix "-m none" case where an entire packet fits in a block and can be read by read_packet_init() diff -r 91dd8328a3ff -r f4232b65b316 packet.c --- a/packet.c Wed Mar 20 22:41:07 2013 +0800 +++ b/packet.c Wed Mar 20 23:13:19 2013 +0800 @@ -133,23 +133,30 @@ /* 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 */ decrypt_packet();