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 UB in Daemonize::privileged_action #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions daemonize/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ use std::env::set_current_dir;
use std::ffi::CString;
use std::fmt;
use std::fs::File;
use std::mem::transmute;
use std::os::unix::ffi::OsStringExt;
use std::os::unix::io::AsRawFd;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -320,9 +319,19 @@ impl<T> Daemonize<T> {
/// Execute `action` just before dropping privileges. Most common use case is to open
/// listening socket. Result of `action` execution will be returned by `start` method.
pub fn privileged_action<N, F: FnOnce() -> N + 'static>(self, action: F) -> Daemonize<N> {
let mut new: Daemonize<N> = unsafe { transmute(self) };
new.privileged_action = Box::new(action);
new
Daemonize {
directory: self.directory,
pid_file: self.pid_file,
chown_pid_file: self.chown_pid_file,
user: self.user,
group: self.group,
umask: self.umask,
root: self.root,
privileged_action: Box::new(action),
stdin: self.stdin,
stdout: self.stdout,
stderr: self.stderr,
}
}

/// Configuration for the child process's standard output stream.
Expand Down