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:
Kane York 2020-07-23 13:02:03 -07:00 committed by kanepyork
parent ec46a594df
commit 9a85694b86
4 changed files with 10 additions and 9 deletions

View file

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