From 698e2531e805c90673fa887f8409fb2fbd7e1cf8 Mon Sep 17 00:00:00 2001 From: lubeilin <1791778603@qq.com> Date: Sat, 30 Dec 2023 12:00:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8F=82=E6=95=B0=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnt-cli/src/config/mod.rs | 3 ++- vnt-cli/src/main.rs | 3 ++- vnt-jni/src/vnt_util.rs | 14 ++++++++++++-- vnt/src/core/mod.rs | 15 ++++++++++++--- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/vnt-cli/src/config/mod.rs b/vnt-cli/src/config/mod.rs index 97415f2..62b1318 100644 --- a/vnt-cli/src/config/mod.rs +++ b/vnt-cli/src/config/mod.rs @@ -158,7 +158,8 @@ pub fn read_config(file_path: &str) -> io::Result<(Config, bool)> { punch_model, file_conf.port, file_conf.first_latency, - ); + ) + .unwrap(); Ok((config, file_conf.cmd)) } diff --git a/vnt-cli/src/main.rs b/vnt-cli/src/main.rs index 1f823c9..f460bce 100644 --- a/vnt-cli/src/main.rs +++ b/vnt-cli/src/main.rs @@ -288,7 +288,8 @@ fn main() { punch_model, port, first_latency, - ); + ) + .unwrap(); (config, cmd) }; println!("version {}", vnt::VNT_VERSION); diff --git a/vnt-jni/src/vnt_util.rs b/vnt-jni/src/vnt_util.rs index 9e6b478..7e69881 100644 --- a/vnt-jni/src/vnt_util.rs +++ b/vnt-jni/src/vnt_util.rs @@ -130,7 +130,7 @@ fn new_sync(env: &mut JNIEnv, config: JObject) -> Result { for addr in stun_server_str.split(",") { stun_server.push(addr.trim().to_string()); } - let config = Config::new( + let config = match Config::new( false, token, device_id, @@ -154,7 +154,17 @@ fn new_sync(env: &mut JNIEnv, config: JObject) -> Result { PunchModel::All, port, first_latency, - ); + ) { + Ok(config) => config, + Err(e) => { + env.throw_new( + "java/lang/RuntimeException", + format!("vnt start error {}", e), + ) + .expect("throw"); + return Err(Error::JavaException); + } + }; match VntUtilSync::new(config) { Ok(vnt_util) => Ok(vnt_util), Err(e) => { diff --git a/vnt/src/core/mod.rs b/vnt/src/core/mod.rs index 78abfe5..0997f35 100644 --- a/vnt/src/core/mod.rs +++ b/vnt/src/core/mod.rs @@ -600,13 +600,22 @@ impl Config { punch_model: PunchModel, port: u16, first_latency: bool, - ) -> Self { + ) -> Result { for x in stun_server.iter_mut() { if !x.contains(":") { x.push_str(":3478"); } } - Self { + if token.is_empty() || token.len() > 128 { + return Err(Error::Stop(String::from("token too long"))); + } + if device_id.is_empty() || device_id.len() > 128 { + return Err(Error::Stop(String::from("device_id too long"))); + } + if name.is_empty() || name.len() > 128 { + return Err(Error::Stop(String::from("name too long"))); + } + Ok(Self { tap, token, device_id, @@ -631,6 +640,6 @@ impl Config { punch_model, port, first_latency, - } + }) } }