]> git.proxmox.com Git - pve-xtermjs.git/commitdiff
termproxy: fix port/fd range check
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 17 Oct 2023 12:57:03 +0000 (14:57 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 17 Oct 2023 12:57:04 +0000 (14:57 +0200)
The valid upper range was swapped, while at it switch from i32::Max to
RawFd::Max, while currently RawFd is a type alias to i32, it's easier
to grasp what's going on and might even change in the future.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
termproxy/src/main.rs

index 5eb14ee3585c3e1bf0d517f51dcddc869abb5785..e9181fbce173b0fb5c5e024f6df77c91216d0f95 100644 (file)
@@ -278,10 +278,10 @@ fn do_main() -> Result<()> {
     let authport: u16 = *matches.get_one("authport").unwrap_or(&85);
     let use_port_as_fd = matches.contains_id("use-port-as-fd");
 
-    if use_port_as_fd && port > u16::MAX as u64 {
-        return Err(format_err!("port too big"));
-    } else if port > i32::MAX as u64 {
-        return Err(format_err!("Invalid FD number"));
+    if use_port_as_fd && port > std::os::fd::RawFd::MAX as u64 {
+        return Err(format_err!("FD too big"));
+    } else if !use_port_as_fd && port > u16::MAX as u64 {
+        return Err(format_err!("invalid port number"));
     }
 
     let (mut tcp_handle, port) =