]> wimlib.net Git - wimlib/commitdiff
mount_image.c: avoid UBSAN warning in wimfs_listxattr()
authorEric Biggers <ebiggers3@gmail.com>
Sun, 2 Apr 2023 06:29:13 +0000 (23:29 -0700)
committerEric Biggers <ebiggers3@gmail.com>
Sun, 2 Apr 2023 06:29:13 +0000 (23:29 -0700)
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

index d3e332a11bb8e3c0446306856585940a2d3b661f..e9922454a37f9e184ac25acca7dbd3607746c01f 100644 (file)
@@ -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;
                        }