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

Do not memcpy from empty source #147

Merged
merged 2 commits into from
Oct 9, 2024
Merged

Conversation

yangchi
Copy link
Contributor

@yangchi yangchi commented Sep 10, 2024

memcpy(dst, src, size) is a Undefined behavior if src is nullptr, even if size is 0. (https://en.cppreference.com/w/c/string/byte/memcpy)
I ran into a case where the input Stack parameter for the scanner serialize call has the has NULL content, 0 size and 0 capacity. And that caused runtime crash when build with UBSAN.

I thought about checking src being nullptr instead of size being 0. But I think if we ever get an input where src is nullptr but size > 0, that's bug somewhere else and we should crash program to surface that. Nullptr + zero size sounds relatively legit to actually hit this function, we just shouldn't try to do memcpy with such empty src. Thus i went with checking the size, not the src ptr. Let me know if people prefer other way. Thanks.

@github-actions github-actions bot added the scanner Related to the external scanner label Sep 10, 2024
@yangchi
Copy link
Contributor Author

yangchi commented Sep 17, 2024

@fwcd could you please take a look? Thank you!

@VladimirMakaev VladimirMakaev merged commit 76f53c4 into fwcd:main Oct 9, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scanner Related to the external scanner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants