Skip to content

Commit

Permalink
strcpy -> memcpy
Browse files Browse the repository at this point in the history
Co-authored-by: Jörg Thalheim <Mic92@users.noreply.github.com>
  • Loading branch information
edolstra and Mic92 authored Sep 17, 2021
1 parent 9d213f1 commit 2d68855
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/libutil/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1726,7 +1726,7 @@ void bind(int fd, const std::string & path)
std::string base(baseNameOf(path));
if (base.size() + 1 >= sizeof(addr.sun_path))
throw Error("socket path '%s' is too long", base);
strcpy(addr.sun_path, base.c_str());
memcpy(addr.sun_path, base.c_str(), base.size() + 1);
if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) == -1)
throw SysError("cannot bind to socket '%s'", path);
_exit(0);
Expand All @@ -1735,7 +1735,7 @@ void bind(int fd, const std::string & path)
if (status != 0)
throw Error("cannot bind to socket '%s'", path);
} else {
strcpy(addr.sun_path, path.c_str());
memcpy(addr.sun_path, path.c_str(), path.size() + 1);
if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) == -1)
throw SysError("cannot bind to socket '%s'", path);
}
Expand All @@ -1755,7 +1755,7 @@ void connect(int fd, const std::string & path)
std::string base(baseNameOf(path));
if (base.size() + 1 >= sizeof(addr.sun_path))
throw Error("socket path '%s' is too long", base);
strcpy(addr.sun_path, base.c_str());
memcpy(addr.sun_path, base.c_str(), base.size() + 1);
if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) == -1)
throw SysError("cannot connect to socket at '%s'", path);
_exit(0);
Expand All @@ -1764,7 +1764,7 @@ void connect(int fd, const std::string & path)
if (status != 0)
throw Error("cannot connect to socket at '%s'", path);
} else {
strcpy(addr.sun_path, path.c_str());
memcpy(addr.sun_path, path.c_str(), path.size() + 1);
if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) == -1)
throw SysError("cannot connect to socket at '%s'", path);
}
Expand Down

0 comments on commit 2d68855

Please sign in to comment.