]> git.ipfire.org Git - thirdparty/haproxy.git/commit
[BUG] stream_sock: BUF_INFINITE_FORWARD broke splice on 64-bit platforms
authorWilly Tarreau <w@1wt.eu>
Sat, 28 Nov 2009 06:47:10 +0000 (07:47 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 28 Nov 2009 06:47:10 +0000 (07:47 +0100)
commita9de333aa58e6cb76f08a50e8ba2c5931184068f
tree619904fc7b822670e10d14c210a402f289045078
parent655dce90d46d3b440cbea5eb4efeca055be6068c
[BUG] stream_sock: BUF_INFINITE_FORWARD broke splice on 64-bit platforms

Yohan Tordjman at Dstorage found that upgrading haproxy to 1.4-dev4
caused truncated objects to be returned. An strace quickly exhibited
the issue which was 100% reproducible :

4297  epoll_wait(0, {}, 10, 0)          = 0
4297  epoll_wait(0, {{EPOLLIN, {u32=7, u64=7}}}, 10, 1000) = 1
4297  splice(0x7, 0, 0x5, 0, 0xffffffffffffffff, 0x3) = -1 EINVAL (Invalid argument)
4297  shutdown(7, 1 /* send */)         = 0
4297  close(7)                          = 0
4297  shutdown(2, 1 /* send */)         = 0
4297  close(2)                          = 0

This is caused by the fact that the forward length is taken from
BUF_INFINITE_FORWARD, which is -1. The problem does not appear
in 32-bit mode because this value is first cast to an unsigned
long, truncating it to 32-bit (4 GB). Setting an upper bound
fixes the issue.

Also, a second error check has been added for splice. If EINVAL
is returned, we fall back to recv().
src/stream_sock.c