mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-03-24 10:35:12 +00:00
Prevent a 0-modulus
If given range for a random is [0, 0), return 0. Modulus 0 is undefined behaviour.
This commit is contained in:
parent
e29e8a49b8
commit
436d18dcaa
|
@ -150,7 +150,17 @@ uint32_t mbedtls_platform_random_in_range( size_t num )
|
||||||
|
|
||||||
mbedtls_hardware_poll( NULL, (unsigned char *) &result, sizeof( result ),
|
mbedtls_hardware_poll( NULL, (unsigned char *) &result, sizeof( result ),
|
||||||
&olen );
|
&olen );
|
||||||
return( result % num );
|
|
||||||
|
if( num == 0 )
|
||||||
|
{
|
||||||
|
result = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result %= num;
|
||||||
|
}
|
||||||
|
|
||||||
|
return( result );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue