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 <hi@alyssa.is> Reviewed-by: glittershark <grfn@gws.fyi>
This commit is contained in:
parent
ec46a594df
commit
9a85694b86
4 changed files with 10 additions and 9 deletions
2
third_party/nix/.clang-tidy
vendored
2
third_party/nix/.clang-tidy
vendored
|
@ -1,3 +1,3 @@
|
||||||
---
|
---
|
||||||
WarningsAsErrors: 'abseil-*'
|
WarningsAsErrors: 'abseil-*,clang-analyzer-security.insecureAPI.strcpy'
|
||||||
...
|
...
|
||||||
|
|
2
third_party/nix/src/libstore/build.cc
vendored
2
third_party/nix/src/libstore/build.cc
vendored
|
@ -2833,7 +2833,7 @@ void DerivationGoal::runChild() {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
strcpy(ifr.ifr_name, "lo");
|
strncpy(ifr.ifr_name, "lo", sizeof("lo"));
|
||||||
ifr.ifr_flags = IFF_UP | IFF_LOOPBACK | IFF_RUNNING;
|
ifr.ifr_flags = IFF_UP | IFF_LOOPBACK | IFF_RUNNING;
|
||||||
if (ioctl(fd.get(), SIOCSIFFLAGS, &ifr) == -1) {
|
if (ioctl(fd.get(), SIOCSIFFLAGS, &ifr) == -1) {
|
||||||
throw SysError("cannot set loopback interface flags");
|
throw SysError("cannot set loopback interface flags");
|
||||||
|
|
7
third_party/nix/src/libstore/remote-store.cc
vendored
7
third_party/nix/src/libstore/remote-store.cc
vendored
|
@ -99,12 +99,13 @@ ref<RemoteStore::Connection> UDSRemoteStore::openConnection() {
|
||||||
|
|
||||||
struct sockaddr_un addr;
|
struct sockaddr_un addr;
|
||||||
addr.sun_family = AF_UNIX;
|
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);
|
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);
|
throw SysError(format("cannot connect to daemon at '%1%'") % socketPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
8
third_party/nix/src/nix-daemon/nix-daemon.cc
vendored
8
third_party/nix/src/nix-daemon/nix-daemon.cc
vendored
|
@ -970,10 +970,10 @@ static void daemonLoop(char** argv) {
|
||||||
|
|
||||||
struct sockaddr_un addr;
|
struct sockaddr_un addr;
|
||||||
addr.sun_family = AF_UNIX;
|
addr.sun_family = AF_UNIX;
|
||||||
if (socketPathRel.size() >= sizeof(addr.sun_path)) {
|
strncpy(addr.sun_path, socketPathRel.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") % socketPathRel);
|
throw Error(format("socket path '%1%' is too long") % socketPathRel);
|
||||||
}
|
}
|
||||||
strcpy(addr.sun_path, socketPathRel.c_str());
|
|
||||||
|
|
||||||
unlink(socketPath.c_str());
|
unlink(socketPath.c_str());
|
||||||
|
|
||||||
|
@ -1125,10 +1125,10 @@ static int _main(int argc, char** argv) {
|
||||||
auto socketName = baseNameOf(socketPath);
|
auto socketName = baseNameOf(socketPath);
|
||||||
auto addr = sockaddr_un{};
|
auto addr = sockaddr_un{};
|
||||||
addr.sun_family = AF_UNIX;
|
addr.sun_family = AF_UNIX;
|
||||||
if (socketName.size() + 1 >= sizeof(addr.sun_path)) {
|
strncpy(addr.sun_path, socketName.c_str(), sizeof(addr.sun_path));
|
||||||
|
if (addr.sun_path[sizeof(addr.sun_path) - 1] != '\0') {
|
||||||
throw Error(format("socket name %1% is too long") % socketName);
|
throw Error(format("socket name %1% is too long") % socketName);
|
||||||
}
|
}
|
||||||
strcpy(addr.sun_path, socketName.c_str());
|
|
||||||
|
|
||||||
if (connect(s, (struct sockaddr*)&addr, sizeof(addr)) == -1) {
|
if (connect(s, (struct sockaddr*)&addr, sizeof(addr)) == -1) {
|
||||||
throw SysError(format("cannot connect to daemon at %1%") %
|
throw SysError(format("cannot connect to daemon at %1%") %
|
||||||
|
|
Loading…
Reference in a new issue