diff options
| author | Visal Vijay <150381094+B2krobbery@users.noreply.github.com> | 2026-03-22 05:09:58 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-21 23:39:58 +0000 |
| commit | 635abdd1c22cbb71216a6d9bf03d93c8d9a30184 (patch) | |
| tree | 802f2eeafceb52428ca8018b916fa402e7583866 /src/xwayland/Server.cpp | |
| parent | a595d0e3c3aa79f88eea2f84526072a83c03b8ee (diff) | |
xwayland: prevent potential buffer overflow in socket path handling (#13797)
Diffstat (limited to 'src/xwayland/Server.cpp')
| -rw-r--r-- | src/xwayland/Server.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/xwayland/Server.cpp b/src/xwayland/Server.cpp index 1ece7454..9d40e1c9 100644 --- a/src/xwayland/Server.cpp +++ b/src/xwayland/Server.cpp @@ -138,24 +138,29 @@ static bool openSockets(std::array<CFileDescriptor, 2>& sockets, int display) { #ifdef __linux__ if (*CREATEABSTRACTSOCKET) { - // cursed... - // but is kept as an option for better compatibility - addr.sun_path[0] = 0; + addr.sun_path[0] = '\0'; path = getSocketPath(display, true); - strncpy(addr.sun_path + 1, path.c_str(), path.length() + 1); + + strncpy(addr.sun_path + 1, path.c_str(), sizeof(addr.sun_path) - 2); } else { path = getSocketPath(display, false); - strncpy(addr.sun_path, path.c_str(), path.length() + 1); + + strncpy(addr.sun_path, path.c_str(), sizeof(addr.sun_path) - 1); + addr.sun_path[sizeof(addr.sun_path) - 1] = '\0'; } #else if (*CREATEABSTRACTSOCKET) { Log::logger->log(Log::WARN, "The abstract XWayland Unix domain socket might be used only on Linux systems. A regular one'll be created instead."); } + path = getSocketPath(display, false); - strncpy(addr.sun_path, path.c_str(), path.length() + 1); + + strncpy(addr.sun_path, path.c_str(), sizeof(addr.sun_path) - 1); + addr.sun_path[sizeof(addr.sun_path) - 1] = '\0'; #endif sockets[0] = CFileDescriptor{createSocket(&addr, path.length())}; + if (!sockets[0].isValid()) return false; |
