From: Paul Seligman Date: Fri, 7 Oct 2022 11:52:31 +0000 (-0400) Subject: ws: minor fixes for web sockets without the CONNECT_ONLY flag X-Git-Tag: curl-7_86_0~98 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b261389dbad6d96c193f6885b216e358905b3ecc;p=thirdparty%2Fcurl.git ws: minor fixes for web sockets without the CONNECT_ONLY flag - Fixed an issue where is_in_callback was getting cleared when using web sockets with debug logging enabled - Ensure the handle is is_in_callback when calling out to fwrite_func - Change the write vs. send_data decision to whether or not the handle is in CONNECT_ONLY mode. - Account for buflen not including the header length in curl_ws_send Closes #9665 --- diff --git a/lib/sendf.c b/lib/sendf.c index 66cec05975..d26b7e7cd7 100644 --- a/lib/sendf.c +++ b/lib/sendf.c @@ -735,9 +735,10 @@ void Curl_debug(struct Curl_easy *data, curl_infotype type, static const char s_infotype[CURLINFO_END][3] = { "* ", "< ", "> ", "{ ", "} ", "{ ", "} " }; if(data->set.fdebug) { + bool inCallback = Curl_is_in_callback(data); Curl_set_in_callback(data, true); (void)(*data->set.fdebug)(data, type, ptr, size, data->set.debugdata); - Curl_set_in_callback(data, false); + Curl_set_in_callback(data, inCallback); } else { switch(type) { diff --git a/lib/ws.c b/lib/ws.c index dbe8788da7..cfd267ee20 100644 --- a/lib/ws.c +++ b/lib/ws.c @@ -334,6 +334,7 @@ size_t Curl_ws_writecb(char *buffer, size_t size /* 1 */, else if(nitems) { unsigned char *frame = NULL; size_t flen = 0; + size_t wrote = 0; CURLcode result; unsigned char *endp; curl_off_t oleft; @@ -383,7 +384,10 @@ size_t Curl_ws_writecb(char *buffer, size_t size /* 1 */, } else { /* deliver the decoded frame to the user callback */ - if(data->set.fwrite_func((char *)frame, 1, flen, writebody_ptr) != flen) + Curl_set_in_callback(data, true); + wrote = data->set.fwrite_func((char *)frame, 1, flen, writebody_ptr); + Curl_set_in_callback(data, false); + if(wrote != flen) return 0; } if(oleft) @@ -681,12 +685,13 @@ CURL_EXTERN CURLcode curl_ws_send(struct Curl_easy *data, const void *buffer, out = data->state.ulbuf; if(buflen) /* for PING and PONG etc there might not be a payload */ - ws_xor(data, buffer, (unsigned char *)out + headlen, buflen - headlen); - if(Curl_is_in_callback(data)) + ws_xor(data, buffer, (unsigned char *)out + headlen, buflen); + + if(data->set.connect_only) + result = Curl_senddata(data, out, buflen + headlen, &written); + else result = Curl_write(data, data->conn->writesockfd, out, buflen + headlen, &written); - else - result = Curl_senddata(data, out, buflen + headlen, &written); infof(data, "WS: wanted to send %zu bytes, sent %zu bytes", headlen + buflen, written);