Skip to content

Commit ebc8e8c

Browse files
committed
clean: use memcpy for ws sha1
1 parent cfe06dd commit ebc8e8c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/roles/ws/client-ws.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ char *
160160
lws_generate_client_ws_handshake(struct lws *wsi, char *p, const char *conn1, size_t p_len)
161161
{
162162
char buf[128], hash[20], key_b64[40], *end = p + p_len;
163+
size_t s;
163164
int n;
164165
#if !defined(LWS_WITHOUT_EXTENSIONS)
165166
const struct lws_extension *ext;
@@ -241,10 +242,13 @@ lws_generate_client_ws_handshake(struct lws *wsi, char *p, const char *conn1, si
241242
/* prepare the expected server accept response */
242243

243244
key_b64[39] = '\0'; /* enforce composed length below buf sizeof */
244-
n = sprintf(buf, "%s258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
245-
key_b64);
246245

247-
lws_SHA1((unsigned char *)buf, (unsigned int)n, (unsigned char *)hash);
246+
s = strlen(key_b64);
247+
memcpy(buf, key_b64, s);
248+
memcpy(buf + s, "258EAFA5-E914-47DA-95CA-C5AB0DC85B11", 36);
249+
s += 36;
250+
251+
lws_SHA1((unsigned char *)buf, (unsigned int)s, (unsigned char *)hash);
248252

249253
lws_b64_encode_string(hash, 20,
250254
wsi->http.ah->initial_handshake_hash_base64,

0 commit comments

Comments
 (0)