Skip to content

Commit 3be7e3c

Browse files
committed
fix(svta): bound the svta ts option to uint32
CodeQL flagged the ts=<n> option as an incorrect integer conversion: strconv.Atoi returns a platform-width int, so a value above 2^32-1 was silently truncated when assigned to the uint32 EventStream@timescale (ts=4294967296 became 0, ts=4294967297 became 1). Use the existing parseUint32 helper, which parses with an explicit 32-bit bound, and reject anything outside it.
1 parent 0f356cd commit 3be7e3c

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

cmd/livesim2/app/svta.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,13 @@ func CreateSVTAConfig(val string) (*SVTAConfig, error) {
110110
case "pod":
111111
cfg.Pod, err = parseSVTABool("pod", v)
112112
case "ts":
113-
n, err := strconv.Atoi(v)
114-
if err != nil || n <= 0 {
115-
return nil, fmt.Errorf("svta ts %q: must be > 0", v)
113+
// parseUint32 bounds the value to the uint32 the EventStream@timescale is,
114+
// so a huge value is rejected rather than silently truncated.
115+
n, err := parseUint32(v)
116+
if err != nil || n == 0 {
117+
return nil, fmt.Errorf("svta ts %q: must be a positive 32-bit integer", v)
116118
}
117-
cfg.Timescale = uint32(n)
119+
cfg.Timescale = n
118120
default:
119121
return nil, fmt.Errorf("unknown svta param %q", key)
120122
}

cmd/livesim2/app/svta_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ func TestCreateSVTAConfig(t *testing.T) {
5959
{desc: "ads too high", val: "30:15;ads=21", err: `svta ads "21": must be 1-20`},
6060
{desc: "negative skip", val: "30:15;skip=-1", err: `svta skip "-1": must be >= 0`},
6161
{desc: "bad click", val: "30:15;click=yes", err: `svta click "yes": must be 0 or 1`},
62-
{desc: "bad timescale", val: "30:15;ts=0", err: `svta ts "0": must be > 0`},
62+
{desc: "zero timescale", val: "30:15;ts=0", err: `svta ts "0": must be a positive 32-bit integer`},
63+
{desc: "negative timescale", val: "30:15;ts=-1", err: `svta ts "-1": must be a positive 32-bit integer`},
64+
{desc: "timescale overflowing uint32", val: "30:15;ts=4294967296",
65+
err: `svta ts "4294967296": must be a positive 32-bit integer`},
6366
}
6467
for _, c := range cases {
6568
t.Run(c.desc, func(t *testing.T) {

0 commit comments

Comments
 (0)