Skip to content

Commit b09a385

Browse files
committed
Duplicate file descriptor in set_key_method
Otherwise it gets closed twice, once by stratisd because it makes a File struct from the raw pointer, and once by the zbus crate. When it is closed twice in a release build there is generally no harm done; but when in a debug build, there is an immediate abort. See #3946 for further details. Signed-off-by: mulhern <[email protected]>
1 parent ddbc17d commit b09a385

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/dbus/manager/manager_3_0/methods.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
44

55
use std::{
6-
os::fd::AsRawFd,
6+
os::fd::{AsRawFd, IntoRawFd},
77
path::PathBuf,
88
sync::{atomic::AtomicU64, Arc},
99
};
@@ -50,6 +50,17 @@ pub async fn set_key_method(
5050
) -> ((bool, bool), u16, String) {
5151
let default_return = (false, false);
5252

53+
let fd = match fd {
54+
Fd::Borrowed(_) => match fd.try_to_owned() {
55+
Ok(Fd::Owned(fd)) => fd.into_raw_fd(),
56+
Ok(_) => unreachable!(),
57+
Err(e) => {
58+
let (rc, rs) = engine_to_dbus_err_tuple(&e.into());
59+
return (default_return, rc, rs);
60+
}
61+
},
62+
Fd::Owned(fd) => fd.into_raw_fd(),
63+
};
5364
match handle_action!(engine.get_key_handler().await.set(key_desc, fd.as_raw_fd())) {
5465
Ok(MappingCreateAction::Created(_)) => (
5566
(true, false),

0 commit comments

Comments
 (0)