Ensure we never return 1 from sodium_init() onload
sodium_init() will return 0 on success, -1 on failure, and 1 if sodium is already loaded and initialized (which is not an error). In the case where libsodium is already initialized and the system is restarted we may return 1 from onload nif function resulting in a crash. - change the call to sodium_init() to check for an error return (-1) and return -1 explicitly in this case, otherwise always return zero at the end of our onload function.
This commit is contained in:
parent
4b4ec373b1
commit
e18f9b7337
@ -41,7 +41,11 @@ static int enacl_crypto_load(ErlNifEnv *env, void **priv_data,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return sodium_init();
|
if (sodium_init() == -1) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* GENERAL ROUTINES
|
/* GENERAL ROUTINES
|
||||||
|
Loading…
x
Reference in New Issue
Block a user