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, - } + }) } }