From 02634200cb24052acb48137c053d65c8e054e73d Mon Sep 17 00:00:00 2001 From: Honza Date: Sun, 14 Apr 2024 15:15:01 +0200 Subject: [PATCH] [#270] Audit issue C: Properly check read() --- .../unixMain/kotlin/cash/z/ecc/android/random/SecureRandom.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bip39-lib/src/unixMain/kotlin/cash/z/ecc/android/random/SecureRandom.kt b/bip39-lib/src/unixMain/kotlin/cash/z/ecc/android/random/SecureRandom.kt index 05dd93d..db596e4 100644 --- a/bip39-lib/src/unixMain/kotlin/cash/z/ecc/android/random/SecureRandom.kt +++ b/bip39-lib/src/unixMain/kotlin/cash/z/ecc/android/random/SecureRandom.kt @@ -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" } }