Change size_t variables to unsigned int's.

These variables are being initialized via calls to `enif_get_uint`,
so it's safer to declare them as unsigned int's rather than size_t's.
Their being used in calls to `enif_alloc_binary`, which takes a size_t
as its size.
However, the resulting ErlNifBinary keeps its size as an unsigned int,
so asking for a size that's an unsigned int should be safe.

This would be problematic in the case where sizeof(size_t) <
sizeof(unsigned), which would mean we're getting fewer bytes allocated
than expected.
Perhaps an explicit check for, for example, `hashSize > MAX_SIZE` would
be good here?
This commit is contained in:
Zane Beckwith 2017-08-14 17:01:50 +00:00
parent e524c2d5c8
commit bf4d61680c

View File

@ -1039,7 +1039,7 @@ ERL_NIF_TERM enif_crypto_onetimeauth_verify(ErlNifEnv *env, int argc, ERL_NIF_TE
static
ERL_NIF_TERM enif_randombytes(ErlNifEnv *env, int argc, ERL_NIF_TERM const argv[])
{
size_t req_size;
unsigned req_size;
ErlNifBinary result;
if ((argc != 1) || (!enif_get_uint(env, argv[0], &req_size))) {
@ -1350,7 +1350,7 @@ static
ERL_NIF_TERM enif_crypto_generichash(ErlNifEnv *env, int argc, ERL_NIF_TERM const argv[]) {
ErlNifBinary hash, message, key;
size_t hashSize;
unsigned hashSize;
// Validate the arguments
if( (argc != 3) ||
@ -1395,7 +1395,7 @@ static
ERL_NIF_TERM enif_crypto_generichash_init(ErlNifEnv *env, int argc, ERL_NIF_TERM const argv[]) {
ErlNifBinary key;
size_t hashSize;
unsigned hashSize;
// Validate the arguments
if( (argc != 2) ||
@ -1447,7 +1447,7 @@ static
ERL_NIF_TERM enif_crypto_generichash_update(ErlNifEnv *env, int argc, ERL_NIF_TERM const argv[]) {
ErlNifBinary message;
size_t hashSize;
unsigned hashSize;
crypto_generichash_state *state;
@ -1484,7 +1484,7 @@ static
ERL_NIF_TERM enif_crypto_generichash_final(ErlNifEnv *env, int argc, ERL_NIF_TERM const argv[]) {
ErlNifBinary hash;
size_t hashSize;
unsigned hashSize;
crypto_generichash_state *state;