internal: avoid buffer overflows with socket paths

This commit is contained in:
vaxerski 2023-04-17 16:38:52 +01:00
parent b6a7be7663
commit a6cfe70428
2 changed files with 3 additions and 3 deletions

View file

@ -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)";

View file

@ -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));