commit | 436d18dcaa1d34d9508be7242d4e0ca7398bbfe0 | [log] [tgz] |
---|---|---|
author | Jarno Lamsa <jarno.lamsa@arm.com> | Thu Oct 03 11:46:30 2019 +0300 |
committer | Jarno Lamsa <jarno.lamsa@arm.com> | Thu Oct 03 13:49:35 2019 +0300 |
tree | 86a0b624833e0739089642fc9bc8812fc9025e5d | |
parent | e29e8a49b84f4dc8c15c51107fa87f5241344350 [diff] [blame] |
Prevent a 0-modulus If given range for a random is [0, 0), return 0. Modulus 0 is undefined behaviour.
diff --git a/library/platform_util.c b/library/platform_util.c index 6ba4112..9461a9c 100644 --- a/library/platform_util.c +++ b/library/platform_util.c
@@ -150,7 +150,17 @@ mbedtls_hardware_poll( NULL, (unsigned char *) &result, sizeof( result ), &olen ); - return( result % num ); + + if( num == 0 ) + { + result = 0; + } + else + { + result %= num; + } + + return( result ); #endif }