summaryrefslogtreecommitdiff
path: root/master.c
diff options
context:
space:
mode:
authorNed T. Crigler <crigler@users.sourceforge.net>2012-07-01 21:44:34 +0000
committerNed T. Crigler <crigler@users.sourceforge.net>2012-07-01 21:44:34 +0000
commitb87fa9970de6a97bdb6afa442267783adc147f4b (patch)
tree77050ffc47dbeca830def16110d4d313dbd51cda /master.c
parentaeb60e6d041cf1995233f5cb6af64fa880200e84 (diff)
Fix error handling for read from stdin in attach.c
attach.c did not correctly handle a read from stdin when read returned an error. The code assigned the return value of read to pkt.len (an unsigned char) before checking the value. This prevented the error check from working correctly, since an unsigned integer can never be < 0. A packet with an invalid length was then sent to the master, which then sent 255 bytes of garbage to the program. Fix the bug in attach.c and the unchecked packet length bug in master.c. Report and initial patch by Enrico Scholz.
Diffstat (limited to 'master.c')
-rw-r--r--master.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/master.c b/master.c
index e65d269..e0351bd 100644
--- a/master.c
+++ b/master.c
@@ -351,7 +351,10 @@ client_activity(struct client *p)
/* Push out data to the program. */
if (pkt.type == MSG_PUSH)
- write(the_pty.fd, pkt.u.buf, pkt.len);
+ {
+ if (pkt.len <= sizeof(pkt.u.buf))
+ write(the_pty.fd, pkt.u.buf, pkt.len);
+ }
/* Attach or detach from the program. */
else if (pkt.type == MSG_ATTACH)