https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117023

Bruno Haible <bruno at clisp dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bruno at clisp dot org

--- Comment #2 from Bruno Haible <bruno at clisp dot org> ---
Created attachment 59394
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59394&action=edit
test case n3322.c

According to
https://sourceware.org/pipermail/libc-alpha/2024-October/160375.html, N3322 has
been accepted for inclusion in ISO C.

The instrumentation of the following functions therefore should NOT produce
runtime errors or crashes any more:

  bsearch
  qsort
  memccpy
  strndup
  wcsncpy
  wcsncmp
  wcsncat

How to reproduce:
$ gcc -fsanitize=undefined,address -O0 -fno-omit-frame-pointer -ggdb n3322.c
$ ./a.out
n3322.c:25:3: runtime error: null pointer passed as argument 2, which is
declared to never be null
n3322.c:26:3: runtime error: null pointer passed as argument 1, which is
declared to never be null
n3322.c:29:3: runtime error: null pointer passed as argument 1, which is
declared to never be null
n3322.c:30:3: runtime error: null pointer passed as argument 2, which is
declared to never be null
n3322.c:35:3: runtime error: null pointer passed as argument 1, which is
declared to never be null
n3322.c:46:3: runtime error: null pointer passed as argument 1, which is
declared to never be null
n3322.c:47:3: runtime error: null pointer passed as argument 2, which is
declared to never be null
n3322.c:52:3: runtime error: null pointer passed as argument 1, which is
declared to never be null
n3322.c:53:3: runtime error: null pointer passed as argument 2, which is
declared to never be null
n3322.c:54:3: runtime error: null pointer passed as argument 1, which is
declared to never be null
n3322.c:54:3: runtime error: null pointer passed as argument 2, which is
declared to never be null
n3322.c:60:3: runtime error: null pointer passed as argument 2, which is
declared to never be null
n3322.c:61:3: runtime error: null pointer passed as argument 1, which is
declared to never be null
AddressSanitizer:DEADLYSIGNAL
=================================================================
==2745541==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc
0x7febd4efef34 bp 0x7ffca7ab7440 sp 0x7ffca7ab6bd8 T0)
==2745541==The signal is caused by a READ memory access.
==2745541==Hint: address points to the zero page.
    #0 0x7febd4efef34 in __sanitizer::internal_wcslen(wchar_t const*)
../../../../gcc-14.2.0/libsanitizer/sanitizer_common/sanitizer_libc.cpp:288
    #1 0x7febd4e710bc in wcsncat
../../../../gcc-14.2.0/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:7093
    #2 0x401a97 in main /home/bruno/n3322.c:61
    #3 0x7febd45b3d8f in __libc_start_call_main
../sysdeps/nptl/libc_start_call_main.h:58
    #4 0x7febd45b3e3f in __libc_start_main_impl ../csu/libc-start.c:392
    #5 0x4011a4 in _start (/home/bruno/a.out+0x4011a4)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV
../../../../gcc-14.2.0/libsanitizer/sanitizer_common/sanitizer_libc.cpp:288 in
__sanitizer::internal_wcslen(wchar_t const*)
==2745541==ABORTING

Dissection of runtime errors:

bsearch:
n3322.c:25:3: runtime error: null pointer passed as argument 2, which is
declared to never be null

qsort:
n3322.c:26:3: runtime error: null pointer passed as argument 1, which is
declared to never be null

memccpy:
n3322.c:29:3: runtime error: null pointer passed as argument 1, which is
declared to never be null
n3322.c:30:3: runtime error: null pointer passed as argument 2, which is
declared to never be null

strndup:
n3322.c:35:3: runtime error: null pointer passed as argument 1, which is
declared to never be null

wcsncpy:
n3322.c:46:3: runtime error: null pointer passed as argument 1, which is
declared to never be null
n3322.c:47:3: runtime error: null pointer passed as argument 2, which is
declared to never be null

wcsncmp:
n3322.c:52:3: runtime error: null pointer passed as argument 1, which is
declared to never be null
n3322.c:53:3: runtime error: null pointer passed as argument 2, which is
declared to never be null
n3322.c:54:3: runtime error: null pointer passed as argument 1, which is
declared to never be null
n3322.c:54:3: runtime error: null pointer passed as argument 2, which is
declared to never be null

wcsncat:
n3322.c:60:3: runtime error: null pointer passed as argument 2, which is
declared to never be null
n3322.c:61:3: runtime error: null pointer passed as argument 1, which is
declared to never be null
and the call to internal_wcslen.

Reply via email to