From b6342cae76fe1e91b1e1abd34c305be438c9cb63 Mon Sep 17 00:00:00 2001 From: Gouryella Date: Sat, 14 Feb 2026 16:45:15 +0800 Subject: [PATCH] feat(cli): Add bandwidth parameter overflow checking and command line parameter passing --- internal/client/cli/http.go | 6 ++++++ internal/client/cli/http_test.go | 2 ++ internal/client/cli/tunnel_helpers.go | 3 +++ 3 files changed, 11 insertions(+) diff --git a/internal/client/cli/http.go b/internal/client/cli/http.go index 807fcdd..2c79f84 100644 --- a/internal/client/cli/http.go +++ b/internal/client/cli/http.go @@ -2,6 +2,7 @@ package cli import ( "fmt" + "math" "strconv" "strings" @@ -154,5 +155,10 @@ func parseBandwidth(s string) (int64, error) { return 0, fmt.Errorf("invalid bandwidth value: %q (use format like 1M, 500K, 1G)", s) } + const maxBandwidth = math.MaxInt64 + if multiplier > 0 && val > maxBandwidth/multiplier { + return 0, fmt.Errorf("bandwidth value too large: %q", s) + } + return val * multiplier, nil } diff --git a/internal/client/cli/http_test.go b/internal/client/cli/http_test.go index 8d1fdb0..0d74594 100644 --- a/internal/client/cli/http_test.go +++ b/internal/client/cli/http_test.go @@ -39,6 +39,8 @@ func TestParseBandwidth(t *testing.T) { {"K", 0, true}, {"1T", 0, true}, {"1KM", 0, true}, + {"9223372036854775807K", 0, true}, // overflow: MaxInt64 * 1024 + {"9999999999999999999G", 0, true}, // overflow: huge * 1G } for _, tt := range tests { diff --git a/internal/client/cli/tunnel_helpers.go b/internal/client/cli/tunnel_helpers.go index 3ece9b3..7d702b1 100644 --- a/internal/client/cli/tunnel_helpers.go +++ b/internal/client/cli/tunnel_helpers.go @@ -30,6 +30,9 @@ func buildDaemonArgs(tunnelType string, args []string, subdomain string, localAd if verbose { daemonArgs = append(daemonArgs, "--verbose") } + if bandwidth != "" { + daemonArgs = append(daemonArgs, "--bandwidth", bandwidth) + } return daemonArgs }