-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Ignore malformed environment strings like glibc does #29297
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
Conversation
r? @brson (rust_highfive has picked a reviewer for you, use r? to override) |
Here's a test program for this behavior:
|
9e8bf6e
to
556a121
Compare
// by an ASCII equals sign '='. Since a variable name must not be | ||
// empty, allow variable names starting with an equals sign. Skip all | ||
// malformed lines. | ||
if input.len() < 1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this could just be if input.len() == 0
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if input.is_empty()
also works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I explicitly chose to use < 1
as I use the index 1
later on. But if you want me to change that, please say so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah let's just stick to is_empty here
Could a linux-specific run-pass test be added for this perhaps? |
Sure, will look into that. |
What kind of test do you think of? I can't really set a malformed environment variable without resorting to the |
@@ -399,24 +399,33 @@ pub unsafe fn environ() -> *mut *const *const c_char { | |||
pub fn env() -> Env { | |||
return unsafe { | |||
let mut environ = *environ(); | |||
if environ as usize == 0 { | |||
if environ == ptr::null() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use .is_null()
.
@tbu- You'd have to maybe write a run-make test with a C program? Not sure if we support that easily. |
Ah yeah I was thinking of a run-pass test that just called execve directly (e.g. translate the C into Rust). I personally prefer to avoid run-make wherever possible. |
@alexcrichton Added a test. |
@bors: r+ 2373415a17e4d9d237b364d787efe4844c8ab98c |
⌛ Testing commit 2373415 with merge 9c2df72... |
💔 Test failed - auto-linux-64-opt |
Clearly caused by my changes, but I'm not sure how to fix that. |
@tbu- If your changes remove LD_LIBRARY_PATH or something similar, try appending something malformed to the environment instead of replacing it. |
Yeah, @eddyb's diagnosis is right. You may be able to get around this with |
@alexcrichton Fixed. |
@bors: r+ 9dc752fa3be645c74eed41c331a7c5351345ea05 |
⌛ Testing commit 9dc752f with merge d383c36... |
💔 Test failed - auto-win-gnu-64-opt |
I have no experience with Windows. Does this fail because |
Oh |
@alexcrichton I believe this one is ready to be merged. |
Thanks! Could you also squash all these commits down? |
96a9627
to
c910006
Compare
@alexcrichton Done. |
Looks like travis is reporting some errors with |
c910006
to
2917cd4
Compare
Fixed. |
@bors: r+ On Sunday, November 15, 2015, tbu- notifications@github.com wrote:
|
📌 Commit 2917cd4 has been approved by |
⌛ Testing commit 2917cd4 with merge fa2f0fd... |
💔 Test failed - auto-linux-64-x-android-t |
.. segmentation fault? That's not supposed to happen. No idea where this comes from. |
It may be the case that the libc on android just doesn't handle calls like this and has bug itself. Either way it's fine to ignore android as well. |
(so long as a comment is added as to why it's ignored on android) |
Otherwise, the iterator and the functions for getting specific environment variables might disagree, for environments like FOOBAR Variable names starting with equals sign are OK: glibc only interprets equals signs not in the first position as separators between variable name and variable value. Instead of skipping them entirely, a leading equals sign is interpreted to be part of the variable name.
2917cd4
to
87243bc
Compare
@alexcrichton Ignored the test, added a comment. |
Otherwise, the iterator and the functions for getting specific environment variables might disagree, for environments like FOOBAR
@tbu-
|
@petrochenkov Can you check whether #29901 fixes that? |
@tbu- |
@petrochenkov Made a pull request to ignore it again: #29910. See also #29911. |
Otherwise, the iterator and the functions for getting specific
environment variables might disagree, for environments like