cURL / Mailing Lists / curl-library / Single Mail

curl-library

curl crash in setsockopt callback

From: Priyanka Shah <priyanka_at_insiemenetworks.com>
Date: Fri, 11 Apr 2014 17:07:02 -0700

I originally sent this to curl-users@, but this might be a more appropriate
place, hence re-posting.

---
Hello,
I need to set a particular socket option through libcurl. I register a
sockopt callback, and set the socket option when callack is called. When I
ran this code, curl crashed with the following trace:
#0  0xf4586435 in sockopt_callback(void*, int, curlsocktype) ()
#1  0xf41f1011 in singleipconnect () from /usr/lib/libcurl.so.5
#2  0xf41f1b04 in Curl_connecthost () from /usr/lib/libcurl.so.5
#3  0xf41e0aa6 in Curl_setup_conn () from /usr/lib/libcurl.so.5
#4  0xf41e0ca6 in Curl_connect () from /usr/lib/libcurl.so.5
#5  0xf41ecd11 in Curl_do_perform () from /usr/lib/libcurl.so.5
#6  0xf41eda43 in curl_easy_perform () from /usr/lib/libcurl.so.5
---------
Here's my code to register for sockopt callback.
            curl_easy_setopt(client, CURLOPT_SOCKOPTDATA, uint32_t data);
            curl_easy_setopt(client, CURLOPT_SOCKOPTFUNCTION,
sockopt_callback);
And this is the callback's implementation:
    int sockopt_callback(void *clientp, curl_socket_t curlfd, curlsocktype
purpose)
    {
        if(clientp == NULL) {
             printf("error");
             return CURL_SOCKOPT_OK;
        }
        uint32_t data = *(uint32_t*) clientp;
        sock_ctx lSockCtx;
        memset(&lSockCtx, 0, sizeof(lSockCtx));
        lSockCtx.data = data;
        if (setsockopt(curlfd, SOL_IP, <opt-name>, &lSockCtx,
sizeof(lSockCtx)) < 0) {
            return CURL_SOCKOPT_ERROR;
        }
        return CURL_SOCKOPT_OK;
    }
I am not sure where to start debugging. Is there something here I am
missing? Any help would be appreciated.
Thanks,
Priyanka.

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2014-04-12