feat(cli): Add bandwidth parameter overflow checking and command line parameter passing

This commit is contained in:
Gouryella
2026-02-14 16:45:15 +08:00
parent 56019f7974
commit b6342cae76
3 changed files with 11 additions and 0 deletions

View File

@@ -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
}

View File

@@ -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 {

View File

@@ -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
}