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 and crash in get_capture #143

Merged
merged 2 commits into from
Feb 19, 2023

Conversation

Timbals
Copy link
Contributor

@Timbals Timbals commented Feb 18, 2023

There are two issues in the get_capture function

  • it assumes the file name will fit into 128 characters and overruns the allocated buffer otherwise
  • it's using CString::from_raw incorrectly (see the safety section in the rust docs)

This PR fixes both.

The second issue was causing crashes with STATUS_HEAP_CORRUPTION for me because it did some funky things when trying to de-allocate the CString (I think it double-frees and the second free also uses the wrong layout; didn't look into it more).

I know you're currently rewriting most of the library but I wanted to share this anyway in case anyone else runs into the same crash.

We previously assumed that the file name of a capture will fit into 128 characters
The previous usage resulted in UB and crashed with `STATUS_HEAP_CORRUPTION` on my system.
Copy link
Owner

@ebkalderon ebkalderon left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the submission, @Timbals! These bugs should be fixed in the other branch tracking the rewrite (using CString::from_vec_unchecked() instead of CStr::from_ptr() to reuse the backing Vec<u8> memory), but I'm very happy to see fixes for both issues land on the main branch in the meantime. It's very much appreciated.

@ebkalderon ebkalderon merged commit ce68c60 into ebkalderon:master Feb 19, 2023
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