Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If Curl_done is called with premature == TRUE we can't pipeline #690

Closed
wants to merge 1 commit into from

Conversation

Andersbakken
Copy link
Contributor

This prevents a crash in the following scenario:

2 (or more) requests are made to the same host and pipelining is enabled.

The first request times out. Curl_done will return early in this block
since conn->send_pipe->size == 1:

if((conn->send_pipe->size + conn->recv_pipe->size != 0 &&
!data->set.reuse_forbid &&
!conn->bits.close)) {
/* Stop if pipeline is not empty and we do not have to close
connection. */
DEBUGF(infof(data, "Connection still in use, no more Curl_done now!\n"));
return CURLE_OK;
}

When the second one fails it will not return early and will in fact
call Curl_disconnect which will free the connection.

When curl_easy_cleanup is called on the first request his easy_conn
pointer will be a dangling pointer and the app will crash.

ASAN output:

==7245==ERROR: AddressSanitizer: heap-use-after-free on address 0xda366d80 at pc 0x986d05b bp 0xd94b16d8 sp 0xd94b16c0
READ of size 4 at 0xda366d80 thread T16 (RESOURCE_HTTP)
    #0 0x986d05a in curl_multi_remove_handle
    #1 0x98a3e2b in Curl_close
    #2 0x985abb5 in curl_easy_cleanup
    #3 0x9777302 in <application frames>
    #4 0xf7b2a016 in __asan::AsanThread::ThreadStart(unsigned long)
    #5 0xf7b16f40 in asan_thread_start(void*)
    #6 0xf7a971a9 in start_thread
    #7 0xf681b02d in clone

0xda366d80 is located 0 bytes inside of 1100-byte region [0xda366d80,0xda3671cc)
freed by thread T16 (RESOURCE_HTTP) here:
    #0 0xf7b1fa5a in free
    #1 0x98b5948 in Curl_disconnect
    #2 0x98d067d in Curl_done
    #3 0x9875a61 in curl_multi_perform
    #4 0x9758a71 in <application frames>
    #5 0xf7b2a016 in __asan::AsanThread::ThreadStart(unsigned long)
    #6 0xf681b02d in clone

This prevents a crash in the following scenario:

2 (or more) requests are made to the same host and pipelining is enabled.

The first request times out. Curl_done will return early in this block
since conn->send_pipe->size == 1:

  if((conn->send_pipe->size + conn->recv_pipe->size != 0 &&
      !data->set.reuse_forbid &&
      !conn->bits.close)) {
    /* Stop if pipeline is not empty and we do not have to close
       connection. */
    DEBUGF(infof(data, "Connection still in use, no more Curl_done now!\n"));
    return CURLE_OK;
  }

When the second one fails it will not return early and will in fact
call Curl_disconnect which will free the connection.

When curl_easy_cleanup is called on the first request his easy_conn
pointer will be a dangling pointer and the app will crash.

ASAN output:

==7245==ERROR: AddressSanitizer: heap-use-after-free on address 0xda366d80 at pc 0x986d05b bp 0xd94b16d8 sp 0xd94b16c0
READ of size 4 at 0xda366d80 thread T16 (RESOURCE_HTTP)
    #0 0x986d05a in curl_multi_remove_handle
    curl#1 0x98a3e2b in Curl_close
    curl#2 0x985abb5 in curl_easy_cleanup
    curl#3 0x9777302 in <application frames>
    curl#4 0xf7b2a016 in __asan::AsanThread::ThreadStart(unsigned long)
    curl#5 0xf7b16f40 in asan_thread_start(void*)
    curl#6 0xf7a971a9 in start_thread
    curl#7 0xf681b02d in clone

0xda366d80 is located 0 bytes inside of 1100-byte region [0xda366d80,0xda3671cc)
freed by thread T16 (RESOURCE_HTTP) here:
    #0 0xf7b1fa5a in free
    curl#1 0x98b5948 in Curl_disconnect
    curl#2 0x98d067d in Curl_done
    curl#3 0x9875a61 in curl_multi_perform
    curl#4 0x9758a71 in <application frames>
    curl#5 0xf7b2a016 in __asan::AsanThread::ThreadStart(unsigned long)
    curl#6 0xf681b02d in clone
jay pushed a commit that referenced this pull request Mar 1, 2016
Prevent a crash if 2 (or more) requests are made to the same host and
pipelining is enabled and the connection does not complete.

Bug: #690
@jay
Copy link
Member

jay commented Mar 2, 2016

Thanks, landed in 3c2ef2a.

@jay jay closed this Mar 2, 2016
@Andersbakken
Copy link
Contributor Author

Thanks.
On Tue, Mar 1, 2016 at 4:01 PM Jay Satiro notifications@github.com wrote:

Closed #690 #690.


Reply to this email directly or view it on GitHub
#690 (comment).

@lock lock bot locked as resolved and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants