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 bugs in handling of socket addresses #52

Merged
merged 3 commits into from Mar 18, 2016
Merged

Conversation

@antrik
Copy link
Contributor

antrik commented Mar 18, 2016

The main commit (the third one, about obtaining '\0'-terminated C strings) addresses a pretty serious bug, which is quite likely causing some intermittent failures. The others are minor.

This also includes a commit with general improvement to some existing test cases, which is not strictly related to the issue at hand, but helped debugging it.

test.rs Outdated
tx2.send(person.clone()).unwrap();
libc::exit(0);
},
pid => pid,

This comment has been minimized.

@pcwalton

pcwalton Mar 18, 2016

Collaborator

Maybe wrap these up in a helper function?

This comment has been minimized.

@antrik

antrik Mar 18, 2016

Author Contributor

Hm... Makes sense I guess. Where shall I put it though? It's used both in tests.rs and in platform/tests.rs...

This comment has been minimized.

@pcwalton

pcwalton Mar 18, 2016

Collaborator

tests.rs would be fine.

This comment has been minimized.

@antrik

antrik Mar 18, 2016

Author Contributor

Eh, actually I meant test.rs and platform/test.rs. So when you say tests.rs, do you actually mean test.rs as well -- or do you mean I should create a separate file for that?...

@@ -459,7 +459,7 @@ impl UnixOneShotServer {
loop {
let path_string = CString::new(b"/tmp/rust-ipc-socket.XXXXXX" as &[u8]).unwrap();
path = path_string.as_bytes().iter().cloned().collect();
if mktemp(path.as_mut_ptr() as *mut c_char) == ptr::null_mut() {
if *mktemp(path.as_mut_ptr() as *mut c_char) == 0 {

This comment has been minimized.

@pcwalton

pcwalton Mar 18, 2016

Collaborator

Ugh! Nice catch.

antrik added 3 commits Mar 18, 2016
The man page says that on error the name is set to an empty string. That
means it's "", i.e. a pointer to '\0' -- *not* a NULL pointer!

This prevented errors in mktemp() from being detected; resulting in
other failures later on, when trying to use the empty string as a socket
address...
CString::as_bytes() yields a slice that does *not* include the
terminating '\0' byte; while the surrounding code subsequently copied
the (unterminated) sequence, and passed the result to various libc
function expecting a terminated string.

This is a serious bug, causing random failure depending on unrelated
memory contents following the copied vector. It triggered more or less
frequent intermittent failures in the test suite (frequency depending on
various other circumstances randomly causing changes in memory
layout/contents); and it seems very likely that similar intermittent
failures were triggered in actual application usage.
Never fill the last byte of the buffer, so the string always stays
terminated.

While not all implementation strictly need that, the man page strongly
recommends it.

This shouldn't actually make a difference for our present use case, as
the (constant) string we are using is much shorter anyways. Still,
better to have it correct -- who knows where this code ends up down the
line...
@antrik antrik force-pushed the antrik:fix-sockaddr branch from 24c40be to b99cd1a Mar 18, 2016
@antrik
Copy link
Contributor Author

antrik commented Mar 18, 2016

I dropped the tests change from this PR, so it doesn't hold up the important fix. I'll submit it separately.

@pcwalton
Copy link
Collaborator

pcwalton commented Mar 18, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Mar 18, 2016

📌 Commit b99cd1a has been approved by pcwalton

@bors-servo
Copy link
Contributor

bors-servo commented Mar 18, 2016

Testing commit b99cd1a with merge ba07b34...

bors-servo added a commit that referenced this pull request Mar 18, 2016
Fix bugs in handling of socket addresses

The main commit (the third one, about obtaining '\0'-terminated C strings) addresses a pretty serious bug, which is quite likely causing some intermittent failures. The others are minor.

This also includes a commit with general improvement to some existing test cases, which is not strictly related to the issue at hand, but helped debugging it.
@bors-servo
Copy link
Contributor

bors-servo commented Mar 18, 2016

☀️ Test successful - travis

@bors-servo bors-servo merged commit b99cd1a into servo:master Mar 18, 2016
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
antrik added a commit to antrik/servo that referenced this pull request Mar 19, 2016
This pulls in servo/ipc-channel#52 , and
especially 8e2357604f7af8869b489b9682a2cf8b58177637, which fixes another
likely cause of intermittent failures on GNU/Linux.
bors-servo added a commit to servo/servo that referenced this pull request Mar 20, 2016
Update ipc-channel for another intermittent bug fix

This pulls in servo/ipc-channel#52 , and
especially 8e2357604f7af8869b489b9682a2cf8b58177637, which fixes another
likely cause of intermittent failures on GNU/Linux.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10092)
<!-- Reviewable:end -->
tyagiarpit added a commit to tyagiarpit/servo that referenced this pull request Mar 23, 2016
This pulls in servo/ipc-channel#52 , and
especially 8e2357604f7af8869b489b9682a2cf8b58177637, which fixes another
likely cause of intermittent failures on GNU/Linux.
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Oct 1, 2019
… fix (from antrik:update-ipc_channel-4); r=KiChjang

This pulls in servo/ipc-channel#52 , and
especially 8e2357604f7af8869b489b9682a2cf8b58177637, which fixes another
likely cause of intermittent failures on GNU/Linux.

Source-Repo: https://github.com/servo/servo
Source-Revision: bcf077c53dcb836692fe52b7edb9bb14a80ff63b

UltraBlame original commit: 12d2b65be1fca4a5de042a6775d8526ef2525606
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request Oct 1, 2019
… fix (from antrik:update-ipc_channel-4); r=KiChjang

This pulls in servo/ipc-channel#52 , and
especially 8e2357604f7af8869b489b9682a2cf8b58177637, which fixes another
likely cause of intermittent failures on GNU/Linux.

Source-Repo: https://github.com/servo/servo
Source-Revision: bcf077c53dcb836692fe52b7edb9bb14a80ff63b

UltraBlame original commit: 12d2b65be1fca4a5de042a6775d8526ef2525606
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request Oct 1, 2019
… fix (from antrik:update-ipc_channel-4); r=KiChjang

This pulls in servo/ipc-channel#52 , and
especially 8e2357604f7af8869b489b9682a2cf8b58177637, which fixes another
likely cause of intermittent failures on GNU/Linux.

Source-Repo: https://github.com/servo/servo
Source-Revision: bcf077c53dcb836692fe52b7edb9bb14a80ff63b

UltraBlame original commit: 12d2b65be1fca4a5de042a6775d8526ef2525606
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.