From 652fdb6b8513bd726b447b121dca93784b2b5d73 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Sat, 1 Apr 2023 23:29:13 -0700 Subject: [PATCH] mount_image.c: avoid UBSAN warning in wimfs_listxattr() When 'list == NULL && size == 0', the statement 'end = list + size' executes 'NULL + 0'. clang's UndefinedBehaviorSanitizer complains that this is undefined: src/mount_image.c:1518:19: runtime error: applying zero offset to null pointer This is questionable, but let's avoid it... --- src/mount_image.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mount_image.c b/src/mount_image.c index d3e332a1..e9922454 100644 --- a/src/mount_image.c +++ b/src/mount_image.c @@ -1517,7 +1517,6 @@ wimfs_listxattr(const char *path, char *list, size_t size) const struct wimfs_context *ctx = wimfs_get_context(); const struct wim_inode *inode; char *p = list; - char *end = list + size; int total_size = 0; if (!(ctx->mount_flags & WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR)) @@ -1553,7 +1552,7 @@ wimfs_listxattr(const char *path, char *list, size_t size) total_size += stream_name_mbs_nbytes + 6; if (size) { - if (end - p < stream_name_mbs_nbytes + 6) { + if (list + size - p < stream_name_mbs_nbytes + 6) { FREE(stream_name_mbs); return -ERANGE; } -- 2.43.0