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

ASAN and/or UBSAN should warn about printf NULL or 0 argument for %s #1804

Open
hannob opened this issue Oct 13, 2024 · 0 comments
Open

ASAN and/or UBSAN should warn about printf NULL or 0 argument for %s #1804

hannob opened this issue Oct 13, 2024 · 0 comments

Comments

@hannob
Copy link

hannob commented Oct 13, 2024

It appears compilers/c libs behave unpredictably when having a format string with %s and passing a NULL or 0 value.

This segfaults with gcc/glibc:

#include <stdio.h>
int main() {
printf("%s\n", NULL);
}

This does not:

#include <stdio.h>
int main() {
printf("test %s\n", NULL);
}

Probably both should be considered undefined. Yet, none of the sanitizers warn about this.

If this is invalid, I think it should be intercepted and trigger an error in ASAN. (Possibly debatable whether ASAN or UBSAN, but it's essentially an invalid pointer, so it's a memory/"address" issue.)

See also discussion here: https://mastodon.social/@[email protected]/113300321719126989
(and rest of thread, it appears the first one crashes due to an optimization towards puts.)

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