fix(lint): use explicit safe type conversions for gosec
Use separate variables with explicit else branches to make type conversions safe and satisfy gosec integer overflow checks.
This commit is contained in:
@@ -120,11 +120,14 @@ func (s *Server) Query(ctx context.Context, req *auditv1.QueryRequest) (*auditv1
|
||||
}
|
||||
|
||||
total := len(protoEntries)
|
||||
var totalInt32 int32
|
||||
if total > math.MaxInt32 {
|
||||
total = math.MaxInt32
|
||||
totalInt32 = math.MaxInt32
|
||||
} else {
|
||||
totalInt32 = int32(total)
|
||||
}
|
||||
return &auditv1.QueryResponse{
|
||||
Entries: protoEntries,
|
||||
Total: int32(total), // Note: This is a simplified total, actual total would require a count query
|
||||
Total: totalInt32, // Note: This is a simplified total, actual total would require a count query
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -82,7 +82,13 @@ func Verify(password, hash string) (bool, error) {
|
||||
if hashLen < 0 || hashLen > math.MaxUint32 {
|
||||
return false, fmt.Errorf("invalid hash length: %d", hashLen)
|
||||
}
|
||||
actualHash := argon2.IDKey([]byte(password), salt, uint32(t), uint32(m), uint8(p), uint32(hashLen))
|
||||
var hashLenUint32 uint32
|
||||
if hashLen > math.MaxUint32 {
|
||||
hashLenUint32 = math.MaxUint32
|
||||
} else {
|
||||
hashLenUint32 = uint32(hashLen)
|
||||
}
|
||||
actualHash := argon2.IDKey([]byte(password), salt, uint32(t), uint32(m), uint8(p), hashLenUint32)
|
||||
|
||||
// Constant-time comparison
|
||||
if subtle.ConstantTimeCompare(expectedHash, actualHash) == 1 {
|
||||
|
||||
Reference in New Issue
Block a user