mirror of https://github.com/xemu-project/xemu.git
contrib/plugins: fix coverity warning in lockstep
Coverity complains that e don't check for a truncation when copying in the path. Bail if we can't copy the whole path into sockaddr. Fixes: CID 1519045 Fixes: CID 1519046 Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20231009164104.369749-25-alex.bennee@linaro.org>
This commit is contained in:
parent
60cb16c0d8
commit
ec7ee95db9
|
@ -245,6 +245,7 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
|
||||||
static bool setup_socket(const char *path)
|
static bool setup_socket(const char *path)
|
||||||
{
|
{
|
||||||
struct sockaddr_un sockaddr;
|
struct sockaddr_un sockaddr;
|
||||||
|
const gsize pathlen = sizeof(sockaddr.sun_path) - 1;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
|
@ -254,7 +255,11 @@ static bool setup_socket(const char *path)
|
||||||
}
|
}
|
||||||
|
|
||||||
sockaddr.sun_family = AF_UNIX;
|
sockaddr.sun_family = AF_UNIX;
|
||||||
g_strlcpy(sockaddr.sun_path, path, sizeof(sockaddr.sun_path) - 1);
|
if (g_strlcpy(sockaddr.sun_path, path, pathlen) >= pathlen) {
|
||||||
|
perror("bad path");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (bind(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr)) < 0) {
|
if (bind(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr)) < 0) {
|
||||||
perror("bind socket");
|
perror("bind socket");
|
||||||
close(fd);
|
close(fd);
|
||||||
|
@ -287,6 +292,7 @@ static bool connect_socket(const char *path)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
struct sockaddr_un sockaddr;
|
struct sockaddr_un sockaddr;
|
||||||
|
const gsize pathlen = sizeof(sockaddr.sun_path) - 1;
|
||||||
|
|
||||||
fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
|
@ -295,7 +301,10 @@ static bool connect_socket(const char *path)
|
||||||
}
|
}
|
||||||
|
|
||||||
sockaddr.sun_family = AF_UNIX;
|
sockaddr.sun_family = AF_UNIX;
|
||||||
g_strlcpy(sockaddr.sun_path, path, sizeof(sockaddr.sun_path) - 1);
|
if (g_strlcpy(sockaddr.sun_path, path, pathlen) >= pathlen) {
|
||||||
|
perror("bad path");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (connect(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr)) < 0) {
|
if (connect(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr)) < 0) {
|
||||||
perror("failed to connect");
|
perror("failed to connect");
|
||||||
|
|
Loading…
Reference in New Issue