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 giving invalid heap-buffer-overflow error #1809

Closed
chiragjain1293 opened this issue Oct 30, 2024 · 2 comments
Closed

Asan giving invalid heap-buffer-overflow error #1809

chiragjain1293 opened this issue Oct 30, 2024 · 2 comments

Comments

@chiragjain1293
Copy link

char *s = calloc(7, 1);
memcpy(s, "1.1.1.1", 7);

char *s2 = strndup(s, 7);

because strndup() is accessing the 8th byte of s, which is obviously an out-of-bounds error. However, ASAN is using its own implementation of this and other functions to detect errors. And in this case the function must not access the nth byte but it does. It is not explicitly stated in strndup() definition but glibc uses strnlen() function to get the size of s, which states that the nth byte will not be accessed. In any case, it is a more-than-reasonable assumption, strndup() does not need to access it so why should it.

@vitalybuka
Copy link
Contributor

Can't reproduce https://godbolt.org/z/KvKEWqr57

@ramosian-glider
Copy link
Member

I tried Clang stable revisions 10-19 with the code Vitaly posted and couldn't reproduce the bug either. Should you decide to reopen the bug, please provide a full reproducer along with the Clang version.

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

No branches or pull requests

3 participants