https://bugs.llvm.org/show_bug.cgi?id=44608

            Bug ID: 44608
           Summary: UBsan warns on access to 0 sized arrays in union
           Product: new-bugs
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedb...@nondot.org
          Reporter: manojgu...@google.com
                CC: htmldevelo...@gmail.com, llvm-bugs@lists.llvm.org

Copied from  Chrome OS bug
https://bugs.chromium.org/p/chromium/issues/detail?id=1043405

One of the programs in Chrome OS uses a 0 sized array inside a union.
ubsan errors on oob accesses to this member. Given that this array is 0 sized,
should accesses to it be treated differently?

Relevant struct snippet from
https://chromium.git.corp.google.com/chromiumos/platform/vboot_reference/+/f5367d598a985520a8c935f68ac90d295c7b8d8e/firmware/2lib/include/2sha.h

struct vb2_hash {
        /* enum vb2_hash_algorithm. Fixed width for serialization.
           Single byte to avoid endianness issues. */
        uint8_t algo;
        /* Padding to align and to match existing CBFS attribute. */
        uint8_t reserved[3];
        /* The actual digest. Can add new types here as required. */
        union {
                uint8_t raw[0]; // triggers ubsan oob checks
#if VB2_SUPPORT_SHA1
                uint8_t sha1[VB2_SHA1_DIGEST_SIZE];
#endif
#if VB2_SUPPORT_SHA256
                uint8_t sha256[VB2_SHA256_DIGEST_SIZE];
#endif
#if VB2_SUPPORT_SHA512
                uint8_t sha512[VB2_SHA512_DIGEST_SIZE];
#endif
        } bytes;  /* This has a name so that it's easy to sizeof(). */
};

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to