]> git.ipfire.org Git - thirdparty/squid.git/commit
Bug 4234: comm_connect_addr uses errno incorrectly
authorAlex Dowad <alexinbeijing@gmail.com>
Sat, 25 Apr 2015 17:21:26 +0000 (10:21 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Sat, 25 Apr 2015 17:21:26 +0000 (10:21 -0700)
commit8630961cbe2e41726edab237fcb66c82b0c66691
tree9c4c442827f5ef04089776b743119d74b13086aa
parent80b2b3c56c7982dbfede26e8aaef9ec83282b032
Bug 4234: comm_connect_addr uses errno incorrectly

comm_connect_addr() uses errno to determine whether library calls like connect()
are successful. Its callers also use errno for extra information on the cause
of any problem. However, after calling library functions like connect(),
comm_connect_addr() calls other library functions which can overwrite errno.

As the errno manpage explains, "a function that succeeds is allowed to change
errno". So even when nothing is wrong, comm_connect_addr() may return an error
flag if libc sets errno. And when something *is* wrong, incorrect error information
may be returned to the caller because errno was overwritten with a different code.

Correct this by using our own error code variable which is set only when a library
call fails. To avoid breaking callers, set errno before returning.
src/comm.cc