Skip to content

Commit 400e1f6

Browse files
aledbfclaude
andcommitted
fix(cli): reject a terminal size flag value int cannot hold
givenInt parsed --terminal-columns/--terminal-rows as int64 and converted to int, so on a 32-bit platform 2147483648 became -2147483648 and was taken as given (code scanning: incorrect conversion between integer types). It now parses at int's size and fails on such a value. The new case in TestGivenIntParsesLikeIntVar fails before the fix under GOARCH=386; on 64-bit platforms nothing changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 37f7fcd commit 400e1f6

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

‎internal/cli/validate.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ type givenInt struct {
6262
}
6363

6464
func (g *givenInt) Set(s string) error {
65-
v, err := strconv.ParseInt(s, 0, 64)
65+
// Parsed at int's size, so a value int cannot hold is an error rather
66+
// than truncated.
67+
v, err := strconv.ParseInt(s, 0, strconv.IntSize)
6668
if err != nil {
6769
return err
6870
}

‎internal/cli/validate_repo_held_test.go‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package cli
22

3-
import "testing"
3+
import (
4+
"math"
5+
"strconv"
6+
"testing"
7+
)
48

59
// An --id-label is <name>=<value>: a name and a value on both sides of an '='.
610
// TS rejects a label without '=', with an empty name or with an empty value.
@@ -96,6 +100,12 @@ func TestGivenIntParsesLikeIntVar(t *testing.T) {
96100
if err := bad.Set("abc"); err == nil || bad.given {
97101
t.Errorf("Set(\"abc\") = %v, givenInt %+v; want an error and not given", err, bad)
98102
}
103+
// A value int cannot hold is an error, never truncated.
104+
tooBig := strconv.FormatUint(uint64(math.MaxInt)+1, 10)
105+
var big givenInt
106+
if err := big.Set(tooBig); err == nil || big.given {
107+
t.Errorf("Set(%q) = %v, givenInt %+v; want an error and not given", tooBig, err, big)
108+
}
99109
}
100110

101111
// The first flag whose value is not one of its choices is the one reported.

0 commit comments

Comments
 (0)