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

Fix undefined behavior in strncpy() call #595

Merged
merged 3 commits into from
Apr 4, 2024

Conversation

LocalSpook
Copy link
Contributor

strncpy()'s pointer parameters are marked restrict, but when file_browser_reload_directory_content() was being called to reload the directory that was currently open:

file_browser_reload_directory_content(browser, browser->directory)

it would try to copy its path buffer to itself, causing undefined behavior. The solution uses memmove(), which can handle overlapping pointers.

Found with Address Sanitizer.

`strncpy()`'s pointer parameters are marked `restrict`, but when
`file_browser_reload_directory_content()` was being called to reload
the directory it already had open, it would try to copy its path
buffer to itself, causing undefined behavior.
example/file_browser.c Outdated Show resolved Hide resolved
example/file_browser.c Outdated Show resolved Hide resolved
Copy link
Contributor

@RobLoach RobLoach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With using nk_memcpy, I think this should be okay.

example/file_browser.c Outdated Show resolved Hide resolved
@RobLoach RobLoach merged commit c8e91e5 into Immediate-Mode-UI:master Apr 4, 2024
1 check passed
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

Successfully merging this pull request may close these issues.

2 participants