diff options
author | Peter Harris <pharris@opentext.com> | 2014-11-17 14:31:24 -0500 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2014-11-30 11:37:56 -0800 |
commit | 4b0d0df34f10a88c10cb23dd50087b59f5c4fece (patch) | |
tree | c8d85aef859a0160670573c13f5bfb5eedf78891 /os | |
parent | 802932d112a3f6a09420be9e4a13fa78ac43840b (diff) |
Fix overflow of ConnectionOutput->size and ->count
When (long) is larger than (int), and when realloc succeeds with sizes
larger than INT_MAX, ConnectionOutput->size and ConnectionOutput->count
overflow and become negative.
When ConnectionOutput->count is negative, InsertIOV does not actually
insert an IOV, and FlushClient goes into an infinite loop of writev(fd,
iov, 0) [an empty list].
Avoid this situation by killing the client when it has more than INT_MAX
unread bytes of data.
Signed-off-by: Peter Harris <pharris@opentext.com>
Reviewed-by: Keith Packard <keithp@keithp.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'os')
-rw-r--r-- | os/io.c | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -971,10 +971,11 @@ FlushClient(ClientPtr who, OsCommPtr oc, const void *__extraBuf, int extraCount) } if (notWritten > oco->size) { - unsigned char *obuf; + unsigned char *obuf = NULL; - obuf = (unsigned char *) realloc(oco->buf, - notWritten + BUFSIZE); + if (notWritten + BUFSIZE <= INT_MAX) { + obuf = realloc(oco->buf, notWritten + BUFSIZE); + } if (!obuf) { _XSERVTransDisconnect(oc->trans_conn); _XSERVTransClose(oc->trans_conn); |