Skip to content

Commit d87997c

Browse files
BenjaminPelletiergithub-advanced-security[bot]mickmis
authored
Fix for code scanning alert no. 2: Incorrect conversion between integer types (#1147)
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Co-authored-by: Mickaël Misbach <[email protected]>
1 parent 86e2eb5 commit d87997c

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

pkg/models/models.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,14 @@ func VersionFromString(s string) (*Version, error) {
112112
}
113113
v := &Version{s: s}
114114

115-
nanos, err := strconv.ParseUint(string(s), versionBase, 64)
115+
nanos, err := strconv.ParseInt(string(s), versionBase, 64)
116116
if err != nil {
117117
return nil, stacktrace.Propagate(err, "Error parsing version to integer")
118118
}
119-
v.t = time.Unix(0, int64(nanos))
119+
if nanos < 0 {
120+
return nil, stacktrace.NewError("Parsed negative value for nanosecond timestamp for version")
121+
}
122+
v.t = time.Unix(0, nanos)
120123
return v, nil
121124
}
122125

pkg/rid/store/cockroach/subscriptions_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func TestStoreDeleteSubscription(t *testing.T) {
159159

160160
// Ensure mismatched versions returns nothing
161161
sub1BadVersion := *sub1
162-
sub1BadVersion.Version, err = dssmodels.VersionFromString("a3cg3tcuhk000")
162+
sub1BadVersion.Version, err = dssmodels.VersionFromString("a3cg3tcuhk00")
163163
require.NoError(t, err)
164164
sub2, err := repo.DeleteSubscription(ctx, &sub1BadVersion)
165165
require.NoError(t, err)

0 commit comments

Comments
 (0)