[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 25/31] contrib/plugins: fix coverity warning in lockstep
From: |
Alex Bennée |
Subject: |
[PATCH 25/31] contrib/plugins: fix coverity warning in lockstep |
Date: |
Mon, 25 Sep 2023 15:48:48 +0100 |
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>
---
contrib/plugins/lockstep.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/contrib/plugins/lockstep.c b/contrib/plugins/lockstep.c
index 682b11feb2..f0cb8792c6 100644
--- a/contrib/plugins/lockstep.c
+++ b/contrib/plugins/lockstep.c
@@ -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)
{
struct sockaddr_un sockaddr;
+ const gsize pathlen = sizeof(sockaddr.sun_path) - 1;
int fd;
fd = socket(AF_UNIX, SOCK_STREAM, 0);
@@ -254,7 +255,11 @@ static bool setup_socket(const char *path)
}
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) {
perror("bind socket");
close(fd);
@@ -287,6 +292,7 @@ static bool connect_socket(const char *path)
{
int fd;
struct sockaddr_un sockaddr;
+ const gsize pathlen = sizeof(sockaddr.sun_path) - 1;
fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd < 0) {
@@ -295,7 +301,10 @@ static bool connect_socket(const char *path)
}
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) {
perror("failed to connect");
--
2.39.2
- [PATCH 11/31] plugins: Check if vCPU is realized, (continued)
- [PATCH 11/31] plugins: Check if vCPU is realized, Alex Bennée, 2023/09/25
- [PATCH 14/31] target/arm: Move the reference to arm-core.xml, Alex Bennée, 2023/09/25
- [PATCH 19/31] gdbstub: Remove gdb_has_xml variable, Alex Bennée, 2023/09/25
- [PATCH 23/31] plugins: Set final instruction count in plugin_gen_tb_end, Alex Bennée, 2023/09/25
- [PATCH 21/31] accel/tcg: Add plugin_enabled to DisasContextBase, Alex Bennée, 2023/09/25
- [RFC PATCH 29/31] sysemu: generalise qtest_warp_clock as qemu_clock_advance_virtual_time, Alex Bennée, 2023/09/25
- [RFC PATCH 27/31] sysemu: add set_virtual_time to accel ops, Alex Bennée, 2023/09/25
- [RFC PATCH 30/31] plugins: add time control API, Alex Bennée, 2023/09/25
- [RFC PATCH 31/31] contrib/plugins: add iops plugin example for cost modelling, Alex Bennée, 2023/09/25
- [PATCH 22/31] target/sh4: Disable decode_gusa when plugins enabled, Alex Bennée, 2023/09/25
- [PATCH 25/31] contrib/plugins: fix coverity warning in lockstep,
Alex Bennée <=
- [PATCH 24/31] contrib/plugins: fix coverity warning in cache, Alex Bennée, 2023/09/25
- [PATCH 18/31] target/ppc: Remove references to gdb_has_xml, Alex Bennée, 2023/09/25
- [PATCH 16/31] gdbstub: Use g_markup_printf_escaped(), Alex Bennée, 2023/09/25
- [RFC PATCH 28/31] qtest: use cpu interface in qtest_clock_warp, Alex Bennée, 2023/09/25
- [PATCH 26/31] contrib/plugins: fix coverity warning in hotblocks, Alex Bennée, 2023/09/25
- [PATCH 17/31] target/arm: Remove references to gdb_has_xml, Alex Bennée, 2023/09/25
- [PATCH 20/31] gdbstub: Replace gdb_regs with an array, Alex Bennée, 2023/09/25