Skip to content

Commit ff923a8

Browse files
committed
Fix buffer underflow when serial peer spews garbage
A board I got spews garbage on hard reset. Sometimes that garbage is IAC and it leads to len here getting negative and the loop eventually underflows the buf. Detect and avoid this silently. Signed-off-by: Ahmad Fatoum <[email protected]>
1 parent a94d4b8 commit ff923a8

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

mux.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ char *answerback;
211211

212212
static void write_receive_buf(const unsigned char *buf, int len)
213213
{
214-
if (!len)
214+
if (len <= 0)
215215
return;
216216

217217
write(STDOUT_FILENO, buf, len);
@@ -306,7 +306,7 @@ static int handle_receive_buf(struct ios_ops *ios, unsigned char *buf, int len)
306306
unsigned char *sendbuf = buf;
307307
int i;
308308

309-
while (len) {
309+
while (len > 0) {
310310
switch (*buf) {
311311
case IAC:
312312
/* BUG: this is telnet specific */

0 commit comments

Comments
 (0)