about summary refs log tree commit diff
path: root/third_party/nix/src/libstore/remote-store.cc
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/nix/src/libstore/remote-store.cc')
-rw-r--r--third_party/nix/src/libstore/remote-store.cc7
1 files changed, 4 insertions, 3 deletions
diff --git a/third_party/nix/src/libstore/remote-store.cc b/third_party/nix/src/libstore/remote-store.cc
index 7c4f3a138fc0..33a6ec310ac1 100644
--- a/third_party/nix/src/libstore/remote-store.cc
+++ b/third_party/nix/src/libstore/remote-store.cc
@@ -99,12 +99,13 @@ ref<RemoteStore::Connection> UDSRemoteStore::openConnection() {
 
   struct sockaddr_un addr;
   addr.sun_family = AF_UNIX;
-  if (socketPath.size() + 1 >= sizeof(addr.sun_path)) {
+  strncpy(addr.sun_path, socketPath.c_str(), sizeof(addr.sun_path));
+  if (addr.sun_path[sizeof(addr.sun_path) - 1] != '\0') {
     throw Error(format("socket path '%1%' is too long") % socketPath);
   }
-  strcpy(addr.sun_path, socketPath.c_str());
 
-  if (::connect(conn->fd.get(), (struct sockaddr*)&addr, sizeof(addr)) == -1) {
+  if (::connect(conn->fd.get(), reinterpret_cast<struct sockaddr*>(&addr),
+                sizeof(addr)) == -1) {
     throw SysError(format("cannot connect to daemon at '%1%'") % socketPath);
   }