1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-13 05:56:03 +01:00

nix-find-roots: Properly fail if the socket filename is too long

Otherwise we get a buffer overflow, and bad things can happen
This commit is contained in:
Théophane Hufschmitt 2022-06-22 10:46:46 +02:00
parent 2d651ad2d0
commit 7299ad523b

View file

@ -124,6 +124,8 @@ int main(int argc, char * * argv)
chdir(socketDir.c_str());
fs::remove(socketFilename);
if (socketFilename.string().size() + 1 >= sizeof(addr.sun_path))
throw Error("socket path '" + socketFilename.string() + "' is too long");
strcpy(addr.sun_path, socketFilename.c_str());
if (bind(mySock, (struct sockaddr*) &addr, sizeof(addr)) == -1) {
throw Error("Cannot bind to socket");