Ensure that termkey_advisereadable() just fails with errno=ENOMEM rather than trying to read() zero bytes

This commit is contained in:
Paul LeoNerd Evans
2012-01-18 10:36:50 +00:00
parent 3474a45b14
commit d64ba87eda
2 changed files with 7 additions and 1 deletions

View File

@@ -949,6 +949,12 @@ TermKeyResult termkey_advisereadable(TermKey *tk)
tk->buffstart = 0;
}
/* Not expecting it ever to be greater but doesn't hurt to handle that */
if(tk->buffcount >= tk->buffsize) {
errno = ENOMEM;
return TERMKEY_RES_ERROR;
}
retry:
len = read(tk->fd, tk->buffer + tk->buffcount, tk->buffsize - tk->buffcount);