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

Undefined behavior in call to strcmp() in acutest_select_() #77

Open
Melkor-1 opened this issue Jun 3, 2024 · 0 comments
Open

Undefined behavior in call to strcmp() in acutest_select_() #77

Melkor-1 opened this issue Jun 3, 2024 · 0 comments

Comments

@Melkor-1
Copy link

Melkor-1 commented Jun 3, 2024

  • In main(), on line 1838, there is this call:

    acutest_cmdline_read_(acutest_cmdline_options_, argc, argc, acutest_cmdline_callback_)

    which on line 1438, calls the callback argument like this:

    ret = callback(opt->id, NULL);

    where callback is acutest_cmdline_callback_). This callback then on line 1681 calls:

    if (acutest_select_(arg) == 0)

    where arg was NULL. This then (on line 1059) calls:

    if (strcmp(acutest_list_[i].name, pattern) == 0)

    Yet pattern, the parameter holding the value of arg, is a null pointer.

    According to ISO C11, 7.1.4, "Use of library functions":

    Each of the following statements applies unless explicitly stated otherwise in the detailed descriptions that follow: If an argument to a function has an invalid value (such as [...] a null pointer [...]) [...], the behavior is undefined.

    The description of strcmp() in 7.24.4 does not state otherwise, so the behavior is undefined, and the above call to strcmp() invokes undefined behavior.

This was found when compiling the code with -fanalyzer with GCC 13.1.

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

No branches or pull requests

1 participant