Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass test suite with sanitizers #165

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

cgzones
Copy link
Contributor

@cgzones cgzones commented Sep 22, 2022

Pass the testsuite when build with sanitizers, e.g. CFLAGS=-O1 -g -fsanitize=address -fsanitize-address-use-after-scope -fsanitize-address-use-after-return=always -fno-omit-frame-pointer -fsanitize=undefined -fsanitize=nullability -fsanitize=implicit-conversion -fsanitize=integer -fsanitize=float-divide-by-zero -fsanitize=local-bounds:

  • Avoid calling memcpy with NULL pointer and length 0
    Found by running the test suite with undefined behavior sanitizer:

    confuse.c:674:18: runtime error: null pointer passed as argument 2, which is declared to never be null
    /usr/include/string.h:44:28: note: nonnull attribute specified here
        #0 0x55f77032e601 in cfg_dupopt_array ./libconfuse/src/confuse.c:674:2
        https://github.com/libconfuse/libconfuse/issues/1 0x55f770328227 in cfg_setopt ./libconfuse/src/confuse.c:1063:25
        https://github.com/libconfuse/libconfuse/pull/2 0x55f77032f537 in cfg_init_defaults ./libconfuse/src/confuse.c:861:4
        https://github.com/libconfuse/libconfuse/issues/3 0x55f770335dbb in cfg_init ./libconfuse/src/confuse.c:1877:2
        https://github.com/libconfuse/libconfuse/issues/4 0x55f770321ff7 in main ./libconfuse/tests/keyval.c:50:8
        https://github.com/libconfuse/libconfuse/issues/5 0x7f4bba429209 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
        https://github.com/libconfuse/libconfuse/pull/6 0x7f4bba4292bb in __libc_start_main csu/../csu/libc-start.c:389:3
        https://github.com/libconfuse/libconfuse/pull/7 0x55f7702623c0 in _start (./libconfuse/tests/keyval+0x3a3c0)
    
  • Avoid implicit integer conversions

    confuse.c:601:30: runtime error: implicit conversion from type 'long' of value -1 (64-bit, signed) to type 'unsigned int' changed the value to 4294967295 (32-bit, unsigned)
        #0 0x55bb8fcd6f30 in cfg_getsec ./libconfuse/src/confuse.c:601:30
        https://github.com/libconfuse/libconfuse/issues/1 0x55bb8fcd23e4 in main ./libconfuse/tests/section_getopt.c:92:2
        https://github.com/libconfuse/libconfuse/pull/2 0x7f380da29209 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
        https://github.com/libconfuse/libconfuse/issues/3 0x7f380da292bb in __libc_start_main csu/../csu/libc-start.c:389:3
        https://github.com/libconfuse/libconfuse/issues/4 0x55bb8fc123b0 in _start (./libconfuse/tests/section_getopt+0x3b3b0)
    
  • tests: check additional calls and results

  • tests: skip test with broken fmemopen under sanitizers
    fmemopen(2) is broken with address and memory sanitizer, see Sanitizers use wrong version of intercepted symbols google/sanitizers#628.

Found by running the test suite with undefined behavior sanitizer:

    confuse.c:674:18: runtime error: null pointer passed as argument 2, which is declared to never be null
    /usr/include/string.h:44:28: note: nonnull attribute specified here
        #0 0x55f77032e601 in cfg_dupopt_array ./libconfuse/src/confuse.c:674:2
        libconfuse#1 0x55f770328227 in cfg_setopt ./libconfuse/src/confuse.c:1063:25
        libconfuse#2 0x55f77032f537 in cfg_init_defaults ./libconfuse/src/confuse.c:861:4
        libconfuse#3 0x55f770335dbb in cfg_init ./libconfuse/src/confuse.c:1877:2
        libconfuse#4 0x55f770321ff7 in main ./libconfuse/tests/keyval.c:50:8
        libconfuse#5 0x7f4bba429209 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
        libconfuse#6 0x7f4bba4292bb in __libc_start_main csu/../csu/libc-start.c:389:3
        libconfuse#7 0x55f7702623c0 in _start (./libconfuse/tests/keyval+0x3a3c0)
    confuse.c:601:30: runtime error: implicit conversion from type 'long' of value -1 (64-bit, signed) to type 'unsigned int' changed the value to 4294967295 (32-bit, unsigned)
        #0 0x55bb8fcd6f30 in cfg_getsec ./libconfuse/src/confuse.c:601:30
        libconfuse#1 0x55bb8fcd23e4 in main ./libconfuse/tests/section_getopt.c:92:2
        libconfuse#2 0x7f380da29209 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
        libconfuse#3 0x7f380da292bb in __libc_start_main csu/../csu/libc-start.c:389:3
        libconfuse#4 0x55bb8fc123b0 in _start (./libconfuse/tests/section_getopt+0x3b3b0)
fmemopen(2) is broken with address and memory sanitizer, see
google/sanitizers#628.
@troglobit
Copy link
Collaborator

With such extensive changes I'd like to see a bit of a motivation/description and reasoning wrt. why you want to make the change. The pull request body that should summarize the patches made just says "No description provided." -- this is super frustrating as a maintainer.

If you want code to be merged in any Open Source project, don't expect the recipient to just intuitively know the why or where you're coming from. Please respect the limited time of maintainers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants