Skip to content

Commit

Permalink
tests: crypto: rand32: Check return code of sys_csrand_get
Browse files Browse the repository at this point in the history
Check the return code of sys_csrand_get when testing the function.

Ignoring it is bad practice and can also be a security issue if users
copy-paste this test code.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
  • Loading branch information
SebastianBoe authored and dleach02 committed Jan 4, 2024
1 parent 67a74e4 commit c25ac48
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tests/crypto/rand32/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ ZTEST(rand32_common, test_rand32)
printk("Generating bulk fill cryptographically secure random numbers\n");

memset(buf, 0, sizeof(buf));
sys_csrand_get(buf, sizeof(buf));

int err = sys_csrand_get(buf, sizeof(buf));

zassert_true(err == 0, "sys_csrand_get returned an error");

for (rnd_cnt = 0; rnd_cnt < (N_VALUES - 1); rnd_cnt++) {
gen = buf[rnd_cnt];
Expand Down

0 comments on commit c25ac48

Please sign in to comment.