cURL / Mailing Lists / curl-library / Single Mail

curl-library

Signal handling problem in libcurl

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Thu, 18 Sep 2008 15:01:57 -0700

There's a problem with the way libcurl currently handles the SIGALRM signal.
It installs a handler for SIGALRM to force a synchronous DNS resolve to time
out after a specified time, which is the only way to abort such a resolve
in some cases. Just before the the DNS resolve takes place it initializes a
longjmp pointer so when the signal comes in the signal handler just does
a siglongjmp, control continues from that saved location and the function
returns an error code.

The problem is that all the following control flow executes effectively
inside the signal handler. Not only is there a risk that libcurl could
call an async handler unsafe function (see signal(7)) during this time,
but it could call a user callback function that could call absolutely
anything. In fact, siglongjmp() itself is not on the POSIX list of
async-safe functions, and that's all the libcurl signal handler calls!

The right approach is probably to find some way to interrupt the resolver
from within the signal handler and have it abort normally with an error
code (a flag set within the signal handler would tell if the abort was
due to timeout or not). That would allow the flow of control to remain
outside the signal handler and avoid this problem. The question is: is
it possible to force a resolver to abort like this (maybe by sending
it another signal), and if so, is it portable?

>>> Dan

-- 
http://www.MoveAnnouncer.com              The web change of address service
          Let webmasters know that your web site has moved
Received on 2008-09-19