fix: limit ipc socket filename length (#396)
This commit is contained in:
parent
3fc24a9c72
commit
fb0e57a014
3 changed files with 19 additions and 7 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -412,7 +412,6 @@ name = "eww"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"base64",
|
|
||||||
"bincode",
|
"bincode",
|
||||||
"cairo-rs",
|
"cairo-rs",
|
||||||
"cairo-sys-rs",
|
"cairo-sys-rs",
|
||||||
|
|
|
@ -62,7 +62,6 @@ tokio-util = "0.6"
|
||||||
sysinfo = "0.16.1"
|
sysinfo = "0.16.1"
|
||||||
|
|
||||||
dyn-clone = "1.0"
|
dyn-clone = "1.0"
|
||||||
base64 = "0.13"
|
|
||||||
wait-timeout = "0.2"
|
wait-timeout = "0.2"
|
||||||
|
|
||||||
notify = "5.0.0-pre.7"
|
notify = "5.0.0-pre.7"
|
||||||
|
|
|
@ -17,6 +17,8 @@ use anyhow::{bail, Context, Result};
|
||||||
use daemon_response::{DaemonResponse, DaemonResponseReceiver};
|
use daemon_response::{DaemonResponse, DaemonResponseReceiver};
|
||||||
use opts::ActionWithServer;
|
use opts::ActionWithServer;
|
||||||
use std::{
|
use std::{
|
||||||
|
collections::hash_map::DefaultHasher,
|
||||||
|
hash::{Hash, Hasher},
|
||||||
os::unix::net,
|
os::unix::net,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
time::Duration,
|
time::Duration,
|
||||||
|
@ -210,7 +212,22 @@ impl EwwPaths {
|
||||||
}
|
}
|
||||||
|
|
||||||
let config_dir = config_dir.canonicalize()?;
|
let config_dir = config_dir.canonicalize()?;
|
||||||
let daemon_id = base64::encode(format!("{}", config_dir.display()));
|
|
||||||
|
let mut hasher = DefaultHasher::new();
|
||||||
|
format!("{}", config_dir.display()).hash(&mut hasher);
|
||||||
|
// daemon_id is a hash of the config dir path to ensure that, given a normal XDG_RUNTIME_DIR,
|
||||||
|
// the absolute path to the socket stays under the 108 bytes limit. (see #387, man 7 unix)
|
||||||
|
let daemon_id = format!("{:x}", hasher.finish());
|
||||||
|
|
||||||
|
let ipc_socket_file = std::env::var("XDG_RUNTIME_DIR")
|
||||||
|
.map(std::path::PathBuf::from)
|
||||||
|
.unwrap_or_else(|_| std::path::PathBuf::from("/tmp"))
|
||||||
|
.join(format!("eww-server_{}", daemon_id));
|
||||||
|
|
||||||
|
// 100 as the limit isn't quite 108 everywhere (i.e 104 on BSD or mac)
|
||||||
|
if format!("{}", ipc_socket_file.display()).len() > 100 {
|
||||||
|
log::warn!("The IPC socket file's absolute path exceeds 100 bytes, the socket may fail to create.");
|
||||||
|
}
|
||||||
|
|
||||||
Ok(EwwPaths {
|
Ok(EwwPaths {
|
||||||
config_dir,
|
config_dir,
|
||||||
|
@ -218,10 +235,7 @@ impl EwwPaths {
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
.unwrap_or_else(|_| PathBuf::from(std::env::var("HOME").unwrap()).join(".cache"))
|
.unwrap_or_else(|_| PathBuf::from(std::env::var("HOME").unwrap()).join(".cache"))
|
||||||
.join(format!("eww_{}.log", daemon_id)),
|
.join(format!("eww_{}.log", daemon_id)),
|
||||||
ipc_socket_file: std::env::var("XDG_RUNTIME_DIR")
|
ipc_socket_file,
|
||||||
.map(std::path::PathBuf::from)
|
|
||||||
.unwrap_or_else(|_| std::path::PathBuf::from("/tmp"))
|
|
||||||
.join(format!("eww-server_{}", daemon_id)),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue