mirror of
https://github.com/Gouryella/drip.git
synced 2026-02-23 12:53:43 +00:00
feat(cli): Add bandwidth parameter overflow checking and command line parameter passing
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user