From f70b99dd575fab79d8a942111a6980431f006818 Mon Sep 17 00:00:00 2001 From: Shinyzenith Date: Fri, 25 Mar 2022 20:47:56 +0530 Subject: [PATCH] [patch] CVE-2022-27818 --- src/daemon.rs | 13 +++++-------- src/server.rs | 3 ++- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/daemon.rs b/src/daemon.rs index 251e757..6b1d07d 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -94,11 +94,6 @@ async fn main() -> Result<(), Box> { log::debug!("Using config file path: {:#?}", config_file_path); - if !config_file_path.exists() { - log::error!("{:#?} doesn't exist", config_file_path); - exit(1); - } - let hotkeys = match config::load(&config_file_path) { Err(e) => { log::error!("Config Error: {}", e); @@ -319,7 +314,9 @@ async fn main() -> Result<(), Box> { } fn sock_send(command: &str) -> std::io::Result<()> { - let mut stream = UnixStream::connect("/tmp/swhkd.sock")?; + let sock_file_path = + String::from(format!("/run/user/{}/swhkd.sock", env::var("PKEXEC_UID").unwrap())); + let mut stream = UnixStream::connect(sock_file_path)?; stream.write_all(command.as_bytes())?; Ok(()) } @@ -402,11 +399,11 @@ pub fn fetch_xdg_config_path() -> std::path::PathBuf { } pub fn seteuid(uid: u32) { - let uid = nix::unistd::Uid::from_raw(uid); + let uid = Uid::from_raw(uid); match nix::unistd::seteuid(uid) { Ok(_) => log::debug!("Dropping privileges..."), Err(e) => { - log::error!("Failed to set UID: {:#?}", e); + log::error!("Failed to set EUID: {:#?}", e); exit(1); } } diff --git a/src/server.rs b/src/server.rs index 0733e20..22fd30f 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1,3 +1,4 @@ +use nix::unistd; use std::io::prelude::*; use std::os::unix::net::UnixListener; use std::{ @@ -12,7 +13,7 @@ fn main() -> std::io::Result<()> { env_logger::init(); let pid_file_path = String::from("/tmp/swhks.pid"); - let sock_file_path = String::from("/tmp/swhkd.sock"); + let sock_file_path = String::from(format!("/run/user/{}/swhkd.sock", unistd::Uid::current())); if Path::new(&pid_file_path).exists() { log::trace!("Reading {} file and checking for running instances.", pid_file_path);