mirror of
https://github.com/GrapheneOS/hardened_malloc.git
synced 2025-05-23 08:21:24 -04:00
perform size checks on various operations
Signed-off-by: Tavi <tavi@divested.dev> Co-authored-by: =?UTF-8?q?Christian=20G=C3=B6ttsche?= <cgzones@googlemail.com>
This commit is contained in:
parent
7481c8857f
commit
2f06cddeb7
46 changed files with 1166 additions and 13 deletions
10
random.c
10
random.c
|
@ -5,6 +5,10 @@
|
|||
#include "random.h"
|
||||
#include "util.h"
|
||||
|
||||
#if CONFIG_BLOCK_OPS_CHECK_SIZE && !defined(HAS_ARM_MTE)
|
||||
#include "musl.h"
|
||||
#endif
|
||||
|
||||
#include <sys/random.h>
|
||||
|
||||
static void get_random_seed(void *buf, size_t size) {
|
||||
|
@ -65,7 +69,7 @@ void get_random_bytes(struct random_state *state, void *buf, size_t size) {
|
|||
|
||||
size_t remaining = RANDOM_CACHE_SIZE - state->index;
|
||||
size_t copy_size = min(size, remaining);
|
||||
memcpy(buf, state->cache + state->index, copy_size);
|
||||
h_memcpy_internal(buf, state->cache + state->index, copy_size);
|
||||
state->index += copy_size;
|
||||
|
||||
buf = (char *)buf + copy_size;
|
||||
|
@ -79,7 +83,7 @@ u16 get_random_u16(struct random_state *state) {
|
|||
if (remaining < sizeof(value)) {
|
||||
refill(state);
|
||||
}
|
||||
memcpy(&value, state->cache + state->index, sizeof(value));
|
||||
h_memcpy_internal(&value, state->cache + state->index, sizeof(value));
|
||||
state->index += sizeof(value);
|
||||
return value;
|
||||
}
|
||||
|
@ -106,7 +110,7 @@ u64 get_random_u64(struct random_state *state) {
|
|||
if (remaining < sizeof(value)) {
|
||||
refill(state);
|
||||
}
|
||||
memcpy(&value, state->cache + state->index, sizeof(value));
|
||||
h_memcpy_internal(&value, state->cache + state->index, sizeof(value));
|
||||
state->index += sizeof(value);
|
||||
return value;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue