aboutsummaryrefslogtreecommitdiff
path: root/termkey.c
diff options
context:
space:
mode:
authorPaul LeoNerd Evans <leonerd@leonerd.org.uk>2012-01-18 10:36:50 +0000
committerPaul LeoNerd Evans <leonerd@leonerd.org.uk>2012-01-18 10:36:50 +0000
commitd64ba87edae62894ca74cfb9d6d8cdd88c213397 (patch)
treefab0f0af85d94b40240c881994f18b52f4130bc3 /termkey.c
parent3474a45b14a131e92e52960dd90e63c12fda275d (diff)
downloadtermo-d64ba87edae62894ca74cfb9d6d8cdd88c213397.tar.gz
termo-d64ba87edae62894ca74cfb9d6d8cdd88c213397.tar.xz
termo-d64ba87edae62894ca74cfb9d6d8cdd88c213397.zip
Ensure that termkey_advisereadable() just fails with errno=ENOMEM rather than trying to read() zero bytes
Diffstat (limited to 'termkey.c')
-rw-r--r--termkey.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/termkey.c b/termkey.c
index 7770d83..a55b106 100644
--- a/termkey.c
+++ b/termkey.c
@@ -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);