cURL / Mailing Lists / curl-library / Single Mail


patch - select.c / Curl_socket_check() interrupted

From: Maxime Larocque <>
Date: Tue, 10 Jul 2012 16:22:33 -0400


We found a problem with ftp transfer using libcurl (7.23 and 7.25)
inside an application which is receiving unix signals (SIGUSR1,
SIGUSR2...) almost continuously. (Linux 2.4, PowerPC, HAVE_POLL_FINE

Curl_socket_check() uses poll() to wait for the socket, and retries it
when a signal is received (EINTR). However, if a signal is received and
it also happens that the timeout has been reached, Curl_socket_check()
returns -1 instead of 0 (indicating an error instead of a timeout).

In our case, the result is an aborted connection even before the ftp
banner is received from the server, and a return value of
CURLE_OUT_OF_MEMORY from curl_easy_perform() (Curl_pp_multi_statemach(),
in pingpong.c, actually returns OOM if Curl_socket_check() fails :-)
Funny to debug on a system on which OOM is a possible cause).

The following patch corrects the problem (for curl 7.26 release, but
look the same as 7.25):

diff -ur curl-7.26.0/lib/select.c curl-7.26.0b/lib/select.c
--- curl-7.26.0/lib/select.c 2012-03-08 14:35:25.000000000 -0500
+++ curl-7.26.0b/lib/select.c 2012-07-10 16:02:13.915651510 -0400
@@ -221,8 +221,10 @@
      if(timeout_ms > 0) {
        pending_ms = (int)(timeout_ms - elapsed_ms);
- if(pending_ms <= 0)
+ if(pending_ms <= 0) {
+ r = 0; /* Simulate a "call timed out" case */
+ }
    } while(r == -1);


It only corrects the source of the problem; not the following related

- Curl_pp_multi_statemach(), in pingpong.c which returns
CURLE_OUT_OF_MEMORY. Curl_socket_check() should not fail anyways, and
I'm not sure which code should be returned...
- the ! HAVE_POLL_FINE case in Curl_socket_check(); it uses select() but
seems to have the same trouble at select.c:309

Otherwise, curl + libssh2 is working well, thanks to all developers!

Maxime Larocque
Orthogone Technologies
Under contract for Accedian Networks

List admin:
Received on 2012-07-10