-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Segfault in je_rallocx after pushing new value to Vec<u8> causing it to resize #27878
Comments
If you have a crash like this, I might suspect some prior memory corruption. This is where you examine all your |
Wow, this looks weird. |
Which fcgi code is this? I can't find a recent version (that compiles) |
Ok this smells of incorrect use of /// Retakes ownership of a CString that was transferred to C.
///
/// The only appropriate argument is a pointer obtained by calling
/// `into_ptr`. The length of the string will be recalculated
/// using the pointer.
|
Thanks for your help. I will check other unsafe code in the project. I have re-worked the old rust-fcgi project to get it to compile on current rust nightly. I am using my local version for now. I will upload the working code if you want to test it out. I am not using I believe the Vec's internal pointer should read as a string literal in the trace output, because it is essentially |
Good point. Yes we need the crashing code to be able to debug this. |
This is the rust-fcgi code I am using. This is the test main.rs I am using to run it:
|
It will be complex to set up a test, as you need to set up mod_proxy_fcgi in Apache to send requests to the listening socket. See here for instructions: I am using this line in my apache config: |
C Strings are a perilous territory in rust. You have to use |
@ashleysommer Does it work if you fix this ashleysommer/rust-fcgi@ba1f119#commitcomment-12760908 ? |
@bluss Yes! Thank you. That fixed it. I found a second call to You are right in pointing out that the (reference here)[https://github.com//issues/27769] that the names of the functions could be improved to prevent this kind of confusion. |
Yep, great! Let's close this as not a bug then. Rust did work correctly — memory unsafety originated in an |
Yes once again Rust is smarter than me. |
Yes, the docs for CString::from_ptr that I quoted in this thread :) |
Im getting this very interesting segfault when using with CStrings in a project Im working on.
I am passing a static
&str
with the contents "REQUEST_METHOD" toget_param()
in the fcgi lib. Theget_param()
method converts that to a CString usingCString::new()
. To do that, the rust CStringnew()
constructor method first converts the &str into aVec<u8>
usinginto()
. It then does a.push(0)
to append a null char, then finally returns a new CString usinginto_boxed_slice
on the Vec.The error occurs on the
.push(0)
line here. TheVec<u8>
is created with an initial size being the length of the string, and to add the new char it must calldouble()
on the Vec to make it bigger. When it does that, the allocator segfaults during the jemalloc reallocation call.I isolated the issue further by first converting the
&str
to aVec<u8>
myself then doing.push(0)
on it before passing it to the CString constructor. The push() still crashes when reallocating, as seen in the pasted trace above.I cannot however, create a minimal reproduction of the error. It only does it in this one library. I have tried multiple basic test cases and they all seem to work fine.
I was using a Nightly from Saturday the 15th of August and I just updated to the Current nightly (18th of August) and it is still the same.
Any suggestions on how I can further debug this? Temporarily, is there any way of creating a CString from a &str without using an intermediate Vec?
The text was updated successfully, but these errors were encountered: