cURL / Mailing Lists / curl-library / Single Mail

curl-library

Crash with SMTP if easy handle is removed from multi handle early

From: Gokhan Sengun <gokhansengun_at_gmail.com>
Date: Thu, 12 Jan 2012 00:34:01 +0200

Hi Folks,

I have encountered random crashes in SMTP regression tests in below
scenario (I guess).

1- An easy handle is added to multi handle
2- After initial processing, easy handle is removed from multi handle
3- Then easy handle is reset for next usage with curl_easy_reset
4- During reset (I guess), application crashes.

Please do not tell me to run the application with a debugger or valgrind to
see the backtrace because then the error does not happen because it is
probably a timing issue with my code causing easy handle to be removed from
the multi handle.

Crash happens (I think) in below line

CURLcode Curl_pp_easy_statemach(struct pingpong *pp)
{
  ...
  curl_socket_t sock = conn->sock[FIRSTSOCKET]; /// -> CRASH HERE

It is probably due to conn variable being NULL.

If I change below code,

static CURLcode smtp_easy_statemach(struct connectdata *conn)
{
  ...
  while(smtpc->state != SMTP_STOP) {
    result = Curl_pp_easy_statemach(pp);

to

static CURLcode smtp_easy_statemach(struct connectdata *conn)
{
  ...
  while(smtpc->state != SMTP_STOP) {
    if(pp->conn)
      result = Curl_pp_easy_statemach(pp);
    else
      break;

I do not have random crashes anymore.

Unfortunately, I do not have enough time to adapt an example code to
reproduce the issue for easy debugging. However I am almost sure that easy
handle is removed before pp->conn is set to a valid conn struct.

Ps: If I have some time available, I will create a test case and hopefully
reproduce this error.

Thanks.

-- 
it is twice as difficult to debug a program as to write it. Therefore, if
you put all of your creativity and effort into writing the program, you are
not smart enough to debug it.

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-01-11