aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2026-01-07 12:46:02 +1100
committerStefano Brivio <sbrivio@redhat.com>2026-01-10 19:27:40 +0100
commit0bd2e6883d560c038e49a3cf68984d63f87ca67a (patch)
tree97bce9580c4da89be997f28f209c49aaf6328ec7
parent2aa63237109b97a55c85e4c86c72db0d055bfe7a (diff)
downloadpasst-0bd2e6883d560c038e49a3cf68984d63f87ca67a.tar
passt-0bd2e6883d560c038e49a3cf68984d63f87ca67a.tar.gz
passt-0bd2e6883d560c038e49a3cf68984d63f87ca67a.tar.bz2
passt-0bd2e6883d560c038e49a3cf68984d63f87ca67a.tar.lz
passt-0bd2e6883d560c038e49a3cf68984d63f87ca67a.tar.xz
passt-0bd2e6883d560c038e49a3cf68984d63f87ca67a.tar.zst
passt-0bd2e6883d560c038e49a3cf68984d63f87ca67a.zip
util: Be more defensive about buffer overruns in read_file()
clang-21.1.7 complains about read_file(), thinking that total_read might come to exceed buf_size, leading to an out of bounds access at the end of the function. In fact, the semantics of read()'s return mean this can't ever happen. But we already have to check for the total_read == buf_size case, so it's basically free to change it to >= and suppress the error. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Reviewed-by: Laurent Vivier <lvivier@redhat.com> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r--util.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/util.c b/util.c
index 2730395..a48f727 100644
--- a/util.c
+++ b/util.c
@@ -715,7 +715,7 @@ static ssize_t read_file(const char *path, char *buf, size_t buf_size)
close(fd);
- if (total_read == buf_size) {
+ if (total_read >= buf_size) {
buf[buf_size - 1] = '\0';
return -ENOBUFS;
}