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

Open
chiragjain1293 opened this issue Oct 30, 2024 · 0 comments
Open

Asan giving invalid heap-buffer-overflow error #1809

chiragjain1293 opened this issue Oct 30, 2024 · 0 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.

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