Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upupdate mktemp to mkdtemp to supress warning mktemp is dangerous #196
Conversation
|
Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @emilio (or someone else) soon. |
| @@ -596,7 +596,7 @@ impl OsIpcOneShotServer { | |||
| loop { | |||
| let path_string = CString::new(&b"/tmp/rust-ipc-socket.XXXXXX"[..]).unwrap(); | |||
| path = path_string.as_bytes_with_nul().iter().cloned().collect(); | |||
| if *mktemp(path.as_mut_ptr() as *mut c_char) == 0 { | |||
| if *mkdtemp(path.as_mut_ptr() as *mut c_char) == 0 { | |||
This comment has been minimized.
This comment has been minimized.
dlrobertson
May 13, 2018
Collaborator
mkdtemp creates a directory right? Wouldn't that cause problems with the subsequent new_sockaddr_un call?
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
dlrobertson
May 13, 2018
Collaborator
We're using mkstemp to basically generate a random path. I'm not sure that mkstemp will work either since it actually opens the file. I think we have a few options.
- Create the path some other way (e.g. with a UUID).
- use mkdtemp and then use some path on top of that.
This comment has been minimized.
This comment has been minimized.
akoserwal
May 14, 2018
Author
@dlrobertson : I think, even with option 1 or 2. problem will be with creating the file. As If we using https://doc.rust-lang.org/std/fs/struct.File.html#method.create. it will be in open mode as mkstemp. I am new to rust/system programming. So, I might be having not clear understanding about the entire scenario.
This comment has been minimized.
This comment has been minimized.
akoserwal
May 15, 2018
Author
@dlrobertson : https://github.com/akoserwal/ipc-channel/blob/feat-mktemp-replacement/src/platform/unix/mod.rs#L603
I tried using uuid & creating a file using File:create & removed mktemp.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
antrik
May 23, 2018
Contributor
@dlrobertson you are evil: first you proposed two different valid approaches, but when he implemented one of them, you suddenly ask why he didn't do it another way... ;-)
This comment has been minimized.
This comment has been minimized.
antrik
May 23, 2018
Contributor
@akoserwal you may have figured it out in the meantime; but just to be sure: the issue here is that we do not want to actually create a regular file. Rather, the bind() system call creates a socket special file -- but we need to find a safe location for bind() to put it.
One way to do this is creating a unique and unguessable name up front. (mktemp() is problematic, because the names it creates are not sufficiently unique/unguessable. Your approach using uuid OTOH should have been fine.)
The other way is to safely create a directory for exclusive use (using mkdtemp() or tempfile::TempDir), and then use any name inside that directory for the socket. That's what you are doing in the newer code.
This comment has been minimized.
This comment has been minimized.
dlrobertson
May 23, 2018
Collaborator
@dlrobertson you are evil: first you proposed two different valid approaches, but when he implemented one of them, you suddenly ask why he didn't do it another way... ;-)
lol yeah. I didn't think of using tempfile early enough. Thought it might make the implementation easier.
akoserwal commentedMay 13, 2018
warning: the use of
mktemp' is dangerous, better usemkstemp' or `mkdtemp'#11