[Bug sanitizer/126842] New: GCC trunk's UBSan misses null destinations in __builtin_memcpy and __builtin_memmove

stuzyf at 163 dot com via Gcc-bugs <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126842

            Bug ID: 126842
           Summary: GCC trunk's UBSan misses null destinations in
                    __builtin_memcpy and __builtin_memmove
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: sanitizer
          Assignee: unassigned at gcc dot gnu.org
          Reporter: stuzyf at 163 dot com
                CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
                    jakub at gcc dot gnu.org, kcc at gcc dot gnu.org
  Target Milestone: ---

GCC trunk's UBSan fails to diagnose null destinations in __builtin_memcpy and
__builtin_memmove, while __builtin_memset correctly reports the error.

Reproducer: https://godbolt.org/z/jh4hcjajv

----------------------
int main ()
{
  int a = 1;
  char b[5];
  __builtin_memcpy ((void *)0, b, sizeof (a));
//   __builtin_memmove ((void *)0, b, sizeof (a));
//   __builtin_memset ((void *)0, 0, sizeof (a));
  return 0;
}
----------------------

With x86 GCC trunk and: -fsanitize=undefined -fno-sanitize-recover=undefined

__builtin_memcpy and __builtin_memmove do not produce a UBSan diagnostic; the
program terminates with SIGSEGV.In contrast, __builtin_memset with a null
destination correctly produces a UBSan diagnostic.

With x86 Clang and -fsanitize=undefined, __builtin_memcpy and __builtin_memmove
produce a UBSan DEADLYSIGNAL report for the null destination.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.