[#270] Audit issue C: Properly check read()

This commit is contained in:
Honza Rychnovský 2024-04-14 15:31:23 +02:00 committed by GitHub
parent 26094e2730
commit fb9233ccc3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 1 deletions

View File

@ -26,7 +26,9 @@ actual class SecureRandom {
bytes.usePinned {
read(randomData, it.addressOf(0), bytes.size.convert())
}
check(result >= 0) {
// Warning: Operator '==' cannot be applied to 'ssize_t /* = Long */' and 'Int'
// Converting both sides to Long to ensure they fit in the range
check(result.toLong() == bytes.size.toLong()) {
"Could not get random number from /dev/urandom"
}
}