From 9a85694b8616f2e10f19440f4db9017d44dfae18 Mon Sep 17 00:00:00 2001 From: Kane York Date: Thu, 23 Jul 2020 13:02:03 -0700 Subject: fix(3p/nix): remove usage of strcpy Change-Id: I86125609f433469a8722c780fd758234211d677e Reviewed-on: https://cl.tvl.fyi/c/depot/+/1381 Tested-by: BuildkiteCI Reviewed-by: Alyssa Ross Reviewed-by: glittershark --- third_party/nix/src/libstore/build.cc | 2 +- third_party/nix/src/libstore/remote-store.cc | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'third_party/nix/src/libstore') diff --git a/third_party/nix/src/libstore/build.cc b/third_party/nix/src/libstore/build.cc index dcc3c7edc7af..da35388d855a 100644 --- a/third_party/nix/src/libstore/build.cc +++ b/third_party/nix/src/libstore/build.cc @@ -2833,7 +2833,7 @@ void DerivationGoal::runChild() { } struct ifreq ifr; - strcpy(ifr.ifr_name, "lo"); + strncpy(ifr.ifr_name, "lo", sizeof("lo")); ifr.ifr_flags = IFF_UP | IFF_LOOPBACK | IFF_RUNNING; if (ioctl(fd.get(), SIOCSIFFLAGS, &ifr) == -1) { throw SysError("cannot set loopback interface flags"); 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 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(&addr), + sizeof(addr)) == -1) { throw SysError(format("cannot connect to daemon at '%1%'") % socketPath); } -- cgit 1.4.1