Skip to content

Commit c5c1929

Browse files
tpantelisskitt
authored andcommitted
Address potential integer overflow in timestamp comparison
Converting int64 subtraction to int could overflow on 32-bit systems. Though unlikely in practice, use comparison instead of subtraction. This was identified by the Cursor AI tool. Signed-off-by: Tom Pantelis <[email protected]>
1 parent cc1e09f commit c5c1929

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

pkg/agent/controller/service_import_conflict.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,12 @@ func sortServiceImportsByTimestamp(siList []runtime.Object, aggregatedType mcsv1
218218
tsA := parseTimestamp(siA)
219219
tsB := parseTimestamp(siB)
220220

221-
if tsA == tsB {
222-
return strings.Compare(siA.Labels[mcsv1a1.LabelSourceCluster], siB.Labels[mcsv1a1.LabelSourceCluster])
221+
if tsA < tsB {
222+
return -1
223+
} else if tsA > tsB {
224+
return 1
223225
}
224226

225-
return int(tsA - tsB)
227+
return strings.Compare(siA.Labels[mcsv1a1.LabelSourceCluster], siB.Labels[mcsv1a1.LabelSourceCluster])
226228
})
227229
}

0 commit comments

Comments
 (0)