cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: [PATCH] libcurl/Curl_resolv_timeout: curl_jmpenv should be set before alarm() call

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Mon, 17 Oct 2011 12:53:27 -0700

On Thu, Oct 13, 2011 at 01:33:05PM +0200, Ettore Del Negro wrote:
> while debugging an issue in a PHP extension, i experienced some
> segfaults caused by libcurl.
> I found out the cause was at hostip.c:506:
>
> siglongjmp(curl_jmpenv, 1);
>
> curl_jmpenv was 0x0.
> That happens when SIGALRM is sent *before* sigsetjmp is called at
> hostip.c:609. This could happens, for example, while debugging or when
> process is descheduled for a time greater than SIGALRM timeout.
> The attached patch simply moves sigsetjmp() before alarm().

That's how it was done before commit 6657f12f. But that commit also added
this comment above the sigsetjmp() call:

        This should be the last thing we do before calling Curl_resolv(),
    as otherwise we'd have to worry about variables that get modified
    before we invoke Curl_resolv() (and thus use "volatile").

This patch breaks that restriction, so I'd like to see a comment explaining
why that doesn't apply in this case, or an update that deals with the issue.
At the very least, I can see this patch opening a race condition; if
the alarm fires after the alarm() call but before prev_alarm is updated,
then the code after clean_up will be using an incorrect value.

>>> Dan
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-10-17