summaryrefslogtreecommitdiff
path: root/hyprctl/src/main.cpp
diff options
context:
space:
mode:
authorVaxry <vaxry@vaxry.net>2026-02-28 15:06:10 +0000
committerVaxry <vaxry@vaxry.net>2026-02-28 15:06:10 +0000
commit362ea7b0f3bb858996198a8d760acbd3397dea22 (patch)
treed55c8f2ab7d368c3379a95b042e1fb0a81f5c961 /hyprctl/src/main.cpp
parentf7114016c6dbf524763038642521892b473f4d36 (diff)
hyprctl: fix buffer overflowing writes to the socket
Diffstat (limited to 'hyprctl/src/main.cpp')
-rw-r--r--hyprctl/src/main.cpp24
1 files changed, 12 insertions, 12 deletions
diff --git a/hyprctl/src/main.cpp b/hyprctl/src/main.cpp
index 7146c635..0a33f3ed 100644
--- a/hyprctl/src/main.cpp
+++ b/hyprctl/src/main.cpp
@@ -228,23 +228,23 @@ int request(std::string_view arg, int minArgs = 0, bool needRoll = false) {
constexpr size_t BUFFER_SIZE = 8192;
char buffer[BUFFER_SIZE] = {0};
- sizeWritten = read(SERVERSOCKET, buffer, BUFFER_SIZE);
-
- if (sizeWritten < 0) {
- if (errno == EWOULDBLOCK)
- log("Hyprland IPC didn't respond in time\n");
- log("Couldn't read (6)");
- return 6;
- }
-
- reply += std::string(buffer, sizeWritten);
-
- while (sizeWritten == BUFFER_SIZE) {
+ // read all data until server closes the connection
+ // this handles partial writes on the server side under high load
+ while (true) {
sizeWritten = read(SERVERSOCKET, buffer, BUFFER_SIZE);
+
if (sizeWritten < 0) {
+ if (errno == EWOULDBLOCK)
+ log("Hyprland IPC didn't respond in time\n");
log("Couldn't read (6)");
return 6;
}
+
+ if (sizeWritten == 0) {
+ // server closed connection, we're done
+ break;
+ }
+
reply += std::string(buffer, sizeWritten);
}