60 lines
2.0 KiB
Diff
60 lines
2.0 KiB
Diff
From 461a4e7a0bf9d951d6819f7291db965d6009ff4a Mon Sep 17 00:00:00 2001
|
|
From: zhangyao2022 <zhangyao108@huawei.com>
|
|
Date: Mon, 4 Dec 2023 20:23:21 +0800
|
|
Subject: [PATCH] fix: fixed parsing SocketMode incorrectly
|
|
|
|
---
|
|
core/coms/socket/src/rentry.rs | 25 ++++++++++++++++++++++++-
|
|
1 file changed, 24 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/core/coms/socket/src/rentry.rs b/core/coms/socket/src/rentry.rs
|
|
index 3a25761..57da556 100755
|
|
--- a/core/coms/socket/src/rentry.rs
|
|
+++ b/core/coms/socket/src/rentry.rs
|
|
@@ -42,6 +42,12 @@ fn deserialize_pathbuf_vec(s: &str) -> Result<Vec<PathBuf>, core::error::Error>
|
|
Ok(res)
|
|
}
|
|
|
|
+fn deserialize_parse_mode(s: &str) -> Result<u32, core::error::Error> {
|
|
+ u32::from_str_radix(s, 8).map_err(|_| core::error::Error::ConfigureError {
|
|
+ msg: format!("Invalid SocketMode: {}", s),
|
|
+ })
|
|
+}
|
|
+
|
|
fn deserialize_netlink_vec(s: &str) -> Result<Vec<String>, core::error::Error> {
|
|
Ok(vec![s.to_string()])
|
|
}
|
|
@@ -92,7 +98,7 @@ pub(super) struct SectionSocket {
|
|
#[entry(multiple, myparser = deserialize_pathbuf_vec)]
|
|
pub Symlinks: Vec<PathBuf>,
|
|
pub PassSecurity: Option<bool>,
|
|
- #[entry(default = 0o666)]
|
|
+ #[entry(default = 0o666, myparser = deserialize_parse_mode)]
|
|
pub SocketMode: u32,
|
|
#[entry(default = "")]
|
|
pub SocketUser: String,
|
|
@@ -408,3 +414,20 @@ impl ReDbTable for SocketReDb<u32, SocketReFrame> {
|
|
self.0.switch_buffer(switch);
|
|
}
|
|
}
|
|
+
|
|
+#[cfg(test)]
|
|
+
|
|
+mod test {
|
|
+ use super::deserialize_parse_mode;
|
|
+
|
|
+ #[test]
|
|
+ fn test_deserialize_parse_mode() {
|
|
+ assert_eq!(deserialize_parse_mode("777").unwrap(), 0o777);
|
|
+ assert_eq!(deserialize_parse_mode("644").unwrap(), 0o644);
|
|
+ assert!(deserialize_parse_mode("-777").is_err());
|
|
+ assert!(deserialize_parse_mode("787").is_err());
|
|
+ assert!(deserialize_parse_mode("777aa").is_err());
|
|
+ assert!(deserialize_parse_mode("aaaaa").is_err());
|
|
+ assert!(deserialize_parse_mode("777 aa").is_err());
|
|
+ }
|
|
+}
|
|
--
|
|
2.33.0
|
|
|