diff options
| author | Dimitri Staessens <dimitri@ouroboros.rocks> | 2026-05-16 15:27:14 +0200 |
|---|---|---|
| committer | Sander Vrijders <sander@ouroboros.rocks> | 2026-05-20 08:17:07 +0200 |
| commit | cbf7f953a49a98adfc4803340475ffeccefbe9fb (patch) | |
| tree | 2881fa378f32e52e7285b3fed22308bb86f1f19c /src | |
| parent | 63d3aa9ab8d8b0b6d8a10362e112a431dcb5b4e9 (diff) | |
| download | ouroboros-cbf7f953a49a98adfc4803340475ffeccefbe9fb.tar.gz ouroboros-cbf7f953a49a98adfc4803340475ffeccefbe9fb.zip | |
lib: Free secure memory on process exit
There was a missing crypt_secure_malloc_fini() in the process
init/fini path.
Also fixes a 0 return from OpenSSL RAND_bytes() being interpreted as
succes instead of failure.
Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks>
Signed-off-by: Sander Vrijders <sander@ouroboros.rocks>
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/dev.c | 6 | ||||
| -rw-r--r-- | src/lib/random.c | 7 |
2 files changed, 9 insertions, 4 deletions
diff --git a/src/lib/dev.c b/src/lib/dev.c index 7e9b7329..6177e50b 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -873,7 +873,7 @@ static void init(int argc, if (crypt_secure_malloc_init(PROC_SECMEM_MAX) < 0) { fprintf(stderr, "FATAL: Could not init secure malloc.\n"); - goto fail_timerwheel; + goto fail_secmem; } #if defined PROC_FLOW_STATS @@ -889,7 +889,9 @@ static void init(int argc, #if defined PROC_FLOW_STATS fail_rib_init: + crypt_secure_malloc_fini(); #endif + fail_secmem: tw_fini(); fail_timerwheel: ssm_flow_set_close(proc.fqset); @@ -947,6 +949,8 @@ static void fini(void) #ifdef PROC_FLOW_STATS rib_fini(); #endif + crypt_secure_malloc_fini(); + tw_fini(); ssm_flow_set_close(proc.fqset); diff --git a/src/lib/random.c b/src/lib/random.c index 96315132..2c9a6c0d 100644 --- a/src/lib/random.c +++ b/src/lib/random.c @@ -47,8 +47,9 @@ int random_buffer(void * buf, gcry_randomize(buf, len, GCRY_STRONG_RANDOM); return 0; #elif defined(HAVE_OPENSSL_RNG) - if (len > 0 && len < INT_MAX) - return RAND_bytes((unsigned char *) buf, (int) len); - return -1; + if (len == 0 || len >= INT_MAX) + return -1; + + return RAND_bytes((unsigned char *) buf, (int) len) == 1 ? 0 : -1; #endif } |
