diff options
| author | vaxerski <43317083+vaxerski@users.noreply.github.com> | 2023-04-17 16:38:52 +0100 |
|---|---|---|
| committer | vaxerski <43317083+vaxerski@users.noreply.github.com> | 2023-04-17 16:38:52 +0100 |
| commit | a6cfe704289795740709dd2397c2a43646ca2d6e (patch) | |
| tree | 55eb7d9cd6d334a9df5873e01f6b1c0b6a5b4099 | |
| parent | b6a7be7663964f1f3939e18216f9246367004ea2 (diff) | |
internal: avoid buffer overflows with socket paths
| -rw-r--r-- | hyprctl/main.cpp | 4 | ||||
| -rw-r--r-- | src/managers/EventManager.cpp | 2 |
2 files changed, 3 insertions, 3 deletions
diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp index 7c939a4c..87c332fb 100644 --- a/hyprctl/main.cpp +++ b/hyprctl/main.cpp @@ -80,7 +80,7 @@ void request(std::string arg, int minArgs = 0) { std::string socketPath = "/tmp/hypr/" + instanceSigStr + "/.socket.sock"; - strcpy(serverAddress.sun_path, socketPath.c_str()); + strncpy(serverAddress.sun_path, socketPath.c_str(), 107); if (connect(SERVERSOCKET, (sockaddr*)&serverAddress, SUN_LEN(&serverAddress)) < 0) { std::cout << "Couldn't connect to " << socketPath << ". (3)"; @@ -143,7 +143,7 @@ void requestHyprpaper(std::string arg) { std::string socketPath = "/tmp/hypr/" + instanceSigStr + "/.hyprpaper.sock"; - strcpy(serverAddress.sun_path, socketPath.c_str()); + strncpy(serverAddress.sun_path, socketPath.c_str(), 107); if (connect(SERVERSOCKET, (sockaddr*)&serverAddress, SUN_LEN(&serverAddress)) < 0) { std::cout << "Couldn't connect to " << socketPath << ". (3)"; diff --git a/src/managers/EventManager.cpp b/src/managers/EventManager.cpp index 3fd63fcb..dd4959b8 100644 --- a/src/managers/EventManager.cpp +++ b/src/managers/EventManager.cpp @@ -67,7 +67,7 @@ void CEventManager::startThread() { sockaddr_un SERVERADDRESS = {.sun_family = AF_UNIX}; std::string socketPath = "/tmp/hypr/" + g_pCompositor->m_szInstanceSignature + "/.socket2.sock"; - strcpy(SERVERADDRESS.sun_path, socketPath.c_str()); + strncpy(SERVERADDRESS.sun_path, socketPath.c_str(), 107); bind(SOCKET, (sockaddr*)&SERVERADDRESS, SUN_LEN(&SERVERADDRESS)); |
