Skip to content

Commit b4f9e0b

Browse files
authored
patch sprintf in uWebsockets to use snprintf (#1164)
Path uWebSockets so it doesn't use sprintf anymore.
1 parent 9747780 commit b4f9e0b

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

cmake/external/uWebSockets.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ endif()
2020

2121
set(uwebsockets_commit_tag 4d94401b9c98346f9afd838556fdc7dce30561eb)
2222
set(patch_file
23-
${CMAKE_CURRENT_LIST_DIR}/../../scripts/git/patches/uWebSockets/0001-fix-want-write-crash.patch)
23+
${CMAKE_CURRENT_LIST_DIR}/../../scripts/git/patches/uWebSockets/0001-fix-want-write-and-sprintf-deprecation.patch)
2424

2525
ExternalProject_Add(
2626
uWebSockets

scripts/git/patches/uWebSockets/0001-fix-want-write-crash.patch scripts/git/patches/uWebSockets/0001-fix-want-write-and-sprintf-deprecation.patch

+21-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1-
From d868ac6f2ce8c6ba8359e33616caeb889e0c57e7 Mon Sep 17 00:00:00 2001
2-
From: "google.com" <google.com>
3-
Date: Wed, 7 Jul 2021 19:00:49 -0400
4-
Subject: [PATCH] fix want_write crash
1+
From 300161c1e2e1414fdd8df7ae6f036a6213c3672f Mon Sep 17 00:00:00 2001
2+
From: "drsanta@google.com" <drsanta@google.com>
3+
Date: Thu, 8 Dec 2022 18:52:28 -0500
4+
Subject: [PATCH] fix want write and sprintf deprecation
55

66
---
7-
src/Socket.h | 34 ++++++++++++++++++----------------
8-
1 file changed, 18 insertions(+), 16 deletions(-)
7+
src/HTTPSocket.h | 2 +-
8+
src/Socket.h | 34 ++++++++++++++++++----------------
9+
2 files changed, 19 insertions(+), 17 deletions(-)
910

11+
diff --git a/src/HTTPSocket.h b/src/HTTPSocket.h
12+
index 5cc7a7f..8b1ab20 100644
13+
--- a/src/HTTPSocket.h
14+
+++ b/src/HTTPSocket.h
15+
@@ -204,7 +204,7 @@ struct HttpResponse {
16+
17+
static size_t transform(const char *src, char *dst, size_t length, TransformData transformData) {
18+
// todo: sprintf is extremely slow
19+
- int offset = transformData.hasHead ? 0 : std::sprintf(dst, "HTTP/1.1 200 OK\r\nContent-Length: %u\r\n\r\n", (unsigned int) length);
20+
+ int offset = transformData.hasHead ? 0 : std::snprintf(dst, length, "HTTP/1.1 200 OK\r\nContent-Length: %u\r\n\r\n", (unsigned int) length);
21+
memcpy(dst + offset, src, length);
22+
return length + offset;
23+
}
1024
diff --git a/src/Socket.h b/src/Socket.h
1125
index 2179ff8..521e798 100644
1226
--- a/src/Socket.h
@@ -55,5 +69,5 @@ index 2179ff8..521e798 100644
5569
sent = ::send(getFd(), message->data, message->length, MSG_NOSIGNAL);
5670
if (sent == (ssize_t) message->length) {
5771
--
58-
2.32.0.93.g670b81a890-goog
72+
2.39.0.rc1.256.g54fd8350bd-goog
5973

0 commit comments

Comments
 (0)