We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
When xhr is reused without any headers, CURLOPT_HTTPHEADER needs to points to NULL. Othrewise, tjs will be segfault.
This is test case:
// tests/test-xhr-headers.js import assert from 'tjs:assert'; const url = 'https://postman-echo.com/get'; const xhr = new XMLHttpRequest(); xhr.open('GET', url, false); xhr.setRequestHeader('Content-Type', 'application/json'); xhr.send(); xhr.open('POST', url, false); xhr.send(); // <== segfault
The following is explicitly set to NULL when there is no header. I am not sure this is curl bug or not.
diff --git a/src/xhr.c b/src/xhr.c index 8171c90..291b604 100644 --- a/src/xhr.c +++ b/src/xhr.c @@ -744,9 +744,7 @@ static JSValue tjs_xhr_send(JSContext *ctx, JSValue this_val, int argc, JSValue curl_easy_setopt(x->curl_h, CURLOPT_POSTFIELDSIZE_LARGE, size); curl_easy_setopt(x->curl_h, CURLOPT_COPYPOSTFIELDS, buf); } - if (x->slist) { - curl_easy_setopt(x->curl_h, CURLOPT_HTTPHEADER, x->slist); - } + curl_easy_setopt(x->curl_h, CURLOPT_HTTPHEADER, x->slist); if (x->async) { curl_multi_add_handle(x->curlm_h, x->curl_h); } else {
The text was updated successfully, but these errors were encountered:
xhr: fix crash when reusing request with headers
22b0d55
Credits go to @junsik, thank you! Fixes: #672
Your fix is sound, I applied it in #673
Sorry, something went wrong.
f2f5a96
Successfully merging a pull request may close this issue.
When xhr is reused without any headers, CURLOPT_HTTPHEADER needs to points to NULL.
Othrewise, tjs will be segfault.
This is test case:
The following is explicitly set to NULL when there is no header.
I am not sure this is curl bug or not.
The text was updated successfully, but these errors were encountered: