Skip to content

Commit c7561bb

Browse files
config: reject HTTP and SOCKS5 port collisions (#79)
Reject configs that set HTTP and SOCKS5 listeners to the same port. Enforced both at config-load and in the UI form so users get a clear error before bind-time failure. Adds a focused regression test.
1 parent f97876d commit c7561bb

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

‎src/bin/ui.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,9 @@ impl FormState {
387387
.map_err(|_| "SOCKS5 port must be a number".to_string())?,
388388
)
389389
};
390+
if socks5_port == Some(listen_port) {
391+
return Err("HTTP and SOCKS5 ports must be different".into());
392+
}
390393
let ids: Vec<String> = self
391394
.script_id
392395
.split(|c: char| c == '\n' || c == ',')

‎src/config.rs‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ impl Config {
189189
"scan_batch_size must be greater than 0".into(),
190190
));
191191
}
192+
if self.socks5_port == Some(self.listen_port) {
193+
return Err(ConfigError::Invalid(
194+
"listen_port and socks5_port must be different".into(),
195+
));
196+
}
192197
Ok(())
193198
}
194199

@@ -310,6 +315,19 @@ mod tests {
310315
let cfg: Config = serde_json::from_str(s).unwrap();
311316
assert!(cfg.validate().is_err());
312317
}
318+
319+
#[test]
320+
fn rejects_same_http_and_socks5_port() {
321+
let s = r#"{
322+
"mode": "apps_script",
323+
"auth_key": "SECRET",
324+
"script_id": "X",
325+
"listen_port": 8085,
326+
"socks5_port": 8085
327+
}"#;
328+
let cfg: Config = serde_json::from_str(s).unwrap();
329+
assert!(cfg.validate().is_err());
330+
}
313331
}
314332

315333
#[cfg(test)]

0 commit comments

Comments
 (0)