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.

Reply via email to