Skip to content

Ignore malformed environment variables on Windows too #29901

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

Merged
merged 2 commits into from
Nov 19, 2015

Conversation

tbu-
Copy link
Contributor

@tbu- tbu- commented Nov 17, 2015

See also #29297.

@rust-highfive
Copy link
Contributor

r? @aturon

(rust_highfive has picked a reviewer for you, use r? to override)

};
Some((OsStringExt::from_wide(k), OsStringExt::from_wide(v)))
}
if s.is_empty() {
Copy link
Member

Choose a reason for hiding this comment

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

This check doesn't need to be here as it was covered above via if *self.cur == 0, that's what indicates the end of the environment variable block.

@alexcrichton
Copy link
Member

I'm a little confused after some investigation here. According to Windows the name of a variable cannot contain an equal sign but in practice it looks like the first character can be an equal sign but no others can be. That would explain what's going on here in MinGW because the actual variable name is =C: where we're interpreting it as the empty string.

I think that this may want to update the parsing to account for that (e.g. allow a leading = sign) but otherwise I don't think that this should start ignoring malformed strings just yet as we don't have any other instances in the wild of it coming up.

@tbu-
Copy link
Contributor Author

tbu- commented Nov 18, 2015

I was under the impression that I read about that leading equals sign from official documentation of Microsoft, but I can't find it anymore. :/

@tbu-
Copy link
Contributor Author

tbu- commented Nov 19, 2015

@alexcrichton What should we do with malformed strings? There's nothing meaningful we can output. Upon encountering a string like FOO, we could either output key="FOO", value=""; key="", value="FOO"; or key="BAR", value="123", all of which are equally wrong. I think the best way to handle malformed strings is to ignore them.

@tbu-
Copy link
Contributor Author

tbu- commented Nov 19, 2015

Also, I think my parsing already treats a leading = as part of the variable name, I copied that from the UNIX counterpart.

@alexcrichton
Copy link
Member

I'm not really sure what the best strategy here is, I don't know what the system is actually generating. For example I'm not sure if it's even possible to see a string like FOO or perhaps even " FOO" (leading space). For now we don't have much documentation one way or another so I think it's best to just handle only the leading = case specially and just preserve some non-panicking behavior for the rest.

@tbu-
Copy link
Contributor Author

tbu- commented Nov 19, 2015

So what do you suggest to do in the "missing equals sign" case? The previous code special-cased it to put the whole thing into the key. My code special-cases it to skip the string.

@alexcrichton
Copy link
Member

I guess ignoring it isn't so bad yeah

@tbu-
Copy link
Contributor Author

tbu- commented Nov 19, 2015

@alexcrichton Addressed your comments.

self.cur = self.cur.offset(len + 1);

// `s` has at least length 1 at this point, because the empty
// string terminates the array of environment variables.
Copy link
Member

Choose a reason for hiding this comment

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

Can you update this comment to mention that the purpose of this slice-after-one is not because we know it has length one but because we want to skip any leading = character?

@alexcrichton
Copy link
Member

I think this can re-un-ignore the test in run-pass as well, right?

@tbu-
Copy link
Contributor Author

tbu- commented Nov 19, 2015

Done.

@alexcrichton
Copy link
Member

@bors: r+ e1740221461089106612fd45ffad80f8805abba6

@bors
Copy link
Collaborator

bors commented Nov 19, 2015

⌛ Testing commit e174022 with merge 4ef5e2a...

@bors
Copy link
Collaborator

bors commented Nov 19, 2015

💔 Test failed - auto-linux-64-nopt-t

tbu- added 2 commits November 19, 2015 20:00
Leading equals symbols are treated as part of the variable name, if
there is no other equality symbol or none at all, the environment string
is ignored.
@tbu- tbu- force-pushed the pr_env_ignore_malformed_windows branch from e174022 to 9b4f16b Compare November 19, 2015 20:02
@tbu-
Copy link
Contributor Author

tbu- commented Nov 19, 2015

Fixed the error, compiled it locally (didn't know you could uncover compilation errors in a Windows module on Linux), squashed the commits.

This might take a few test cycles to complete, I don't have a Windows machine where I can test the build.

@alexcrichton
Copy link
Member

@bors: r+ 9b4f16b

bors added a commit that referenced this pull request Nov 19, 2015
@bors
Copy link
Collaborator

bors commented Nov 19, 2015

⌛ Testing commit 9b4f16b with merge 6861c51...

@bors bors merged commit 9b4f16b into rust-lang:master Nov 19, 2015
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.

5 participants