From 00176c9514950a58e8718229458bd568d6b5ea3b Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Thu, 14 Mar 2019 17:53:45 -0700 Subject: [PATCH] fix(sway): ipc client crash when compiled with -D_GLIBCXX_ASSERTIONS reserve() does not change string size and any access beyond data() + size() is UB --- src/modules/sway/ipc/client.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/modules/sway/ipc/client.cpp b/src/modules/sway/ipc/client.cpp index 8205af23..e23c787e 100644 --- a/src/modules/sway/ipc/client.cpp +++ b/src/modules/sway/ipc/client.cpp @@ -64,7 +64,7 @@ struct waybar::modules::sway::Ipc::ipc_response waybar::modules::sway::Ipc::recv(int fd) const { std::string header; - header.reserve(ipc_header_size_); + header.resize(ipc_header_size_); auto data32 = reinterpret_cast(header.data() + ipc_magic_.size()); size_t total = 0; @@ -83,7 +83,7 @@ struct waybar::modules::sway::Ipc::ipc_response total = 0; std::string payload; - payload.reserve(data32[0] + 1); + payload.resize(data32[0]); while (total < data32[0]) { auto res = ::recv(fd, payload.data() + total, data32[0] - total, 0); if (res < 0) { @@ -91,7 +91,6 @@ struct waybar::modules::sway::Ipc::ipc_response } total += res; } - payload[data32[0]] = 0; return { data32[0], data32[1], &payload.front() }; } @@ -100,7 +99,7 @@ struct waybar::modules::sway::Ipc::ipc_response const std::string& payload) const { std::string header; - header.reserve(ipc_header_size_); + header.resize(ipc_header_size_); auto data32 = reinterpret_cast(header.data() + ipc_magic_.size()); memcpy(header.data(), ipc_magic_.c_str(), ipc_magic_.size()); data32[0] = payload.size();