Skip to content

Commit b026a7c

Browse files
committed
fix(linux): calling getrandom() outside assert()
* Expressions inside assert are completely removed in release builds
1 parent e486f3b commit b026a7c

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

components/esp_hw_support/port/linux/esp_random.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,29 @@ static void __attribute__((constructor)) esp_random_init(void) { }
1717
uint32_t esp_random(void)
1818
{
1919
uint32_t random_number;
20-
assert(getentropy(&random_number, sizeof(random_number)) == 0);
20+
int result = getentropy(&random_number, sizeof(random_number));
21+
assert(result == 0);
22+
(void)result;
2123
return random_number;
2224
}
2325

2426
void esp_fill_random(void *buf, size_t len)
2527
{
2628
assert(buf != NULL);
29+
int result;
2730

2831
// Note that we can't use getentropy() with len > 256 directly (see getentropy man page),
2932
// hence reading in chunks
3033
const size_t FULL_CHUNKS_NUM = (len / GETENTROPY_MAX_LEN);
3134
const size_t REST_CHUNK_SIZE = len % GETENTROPY_MAX_LEN;
3235

3336
for (size_t chunk_num = 0; chunk_num < FULL_CHUNKS_NUM; chunk_num++) {
34-
assert(getentropy(buf + chunk_num * GETENTROPY_MAX_LEN, GETENTROPY_MAX_LEN) == 0);
37+
result = getentropy(buf + chunk_num * GETENTROPY_MAX_LEN, GETENTROPY_MAX_LEN);
38+
assert(result == 0);
39+
(void)result;
3540
}
3641

37-
assert(getentropy(buf + FULL_CHUNKS_NUM * GETENTROPY_MAX_LEN, REST_CHUNK_SIZE) == 0);
42+
result = getentropy(buf + FULL_CHUNKS_NUM * GETENTROPY_MAX_LEN, REST_CHUNK_SIZE);
43+
assert(result == 0);
44+
(void)result;
3845
}

0 commit comments

Comments
 (0)