]> git.ipfire.org Git - thirdparty/squid.git/commit
Bug 4234: comm_connect_addr uses errno incorrectly
authorAlex Dowad <alexinbeijing@gmail.com>
Sun, 26 Apr 2015 16:48:02 +0000 (09:48 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Sun, 26 Apr 2015 16:48:02 +0000 (09:48 -0700)
commit003464eb3856d4a15e6a2fc643b8db65187edfc3
treec8b62b9fa67e15736b9c11510f41194fd9b3372b
parent88a92b189a0497d1dc3fcac6b56f7dce7fb8eaa5
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