Skip to content

Commit

Permalink
curl: fix WS crash
Browse files Browse the repository at this point in the history
  • Loading branch information
saghul committed Sep 26, 2023
1 parent 4a07597 commit 4d4735d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/curl-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ int tjs_curl_load_http(DynBuf *dbuf, const char *url) {
}

static void check_multi_info(TJSRuntime *qrt) {
char *done_url;
CURLMsg *message;
int pending;

Expand All @@ -135,6 +134,12 @@ static void check_multi_info(TJSRuntime *qrt) {
tjs_curl_private_t *curl_private = NULL;
curl_easy_getinfo(easy_handle, CURLINFO_PRIVATE, &curl_private);
CHECK_NOT_NULL(curl_private);
/**
* This is an ugly workaround. The WS code uses a _different_ private
* struct and we need to tell them apart.
*/
if (curl_private->magic != TJS__CURL_PRIVATE_MAGIC)
break;
CHECK_NOT_NULL(curl_private->done_cb);
curl_private->done_cb(message, curl_private->arg);

Expand Down
2 changes: 2 additions & 0 deletions src/curl-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@

#include <curl/curl.h>

#define TJS__CURL_PRIVATE_MAGIC 0xde4dc0d3

typedef void (*tjs_curl_done_cb)(CURLMsg *message, void *arg);
typedef struct {
uint32_t magic;
void *arg;
tjs_curl_done_cb done_cb;
} tjs_curl_private_t;
Expand Down
1 change: 1 addition & 0 deletions src/xhr.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ static JSValue tjs_xhr_constructor(JSContext *ctx, JSValueConst new_target, int
x->events[i] = JS_UNDEFINED;
}

x->curl_private.magic = TJS__CURL_PRIVATE_MAGIC;
x->curl_private.arg = x;
x->curl_private.done_cb = curlm__done_cb;

Expand Down

0 comments on commit 4d4735d

Please sign in to comment.