diff options
author | Ladar Levison <ladar@lavabit.com> | 2018-11-28 13:27:59 +0300 |
---|---|---|
committer | Ladar Levison <ladar@lavabit.com> | 2018-11-28 13:27:59 +0300 |
commit | 5d13fb47787719d50c8d1e12b7381ad54635f531 (patch) | |
tree | 20b2b43ae4f0dff69347254d93ee20cfabd9db10 /src | |
parent | 9282bd8d94dd5d1476c15e173d81c9122483ea28 (diff) |
Various data type tweaks to avoid invalid comparisons, access.
Diffstat (limited to 'src')
-rw-r--r-- | src/core/host/ip.c | 6 | ||||
-rw-r--r-- | src/providers/dime/signet/keys.c | 2 | ||||
-rw-r--r-- | src/providers/prime/messages/chunks/chunks.c | 12 | ||||
-rw-r--r-- | src/providers/prime/prime.h | 2 | ||||
-rw-r--r-- | src/providers/prime/transposition/armored/pem.c | 2 | ||||
-rw-r--r-- | src/providers/prime/transposition/binary/fields.c | 3 | ||||
-rw-r--r-- | src/web/portal/endpoint.c | 2 |
7 files changed, 16 insertions, 13 deletions
diff --git a/src/core/host/ip.c b/src/core/host/ip.c index fb09ad32..4258a675 100644 --- a/src/core/host/ip.c +++ b/src/core/host/ip.c @@ -263,7 +263,7 @@ stringer_t * ip_subnet(ip_t *address, stringer_t *output) { // For IPv4 addresses use the first 24 bits, out of the total 32 bits available. if (address->family == AF_INET) { - len = st_sprint(result, "%hhu.%hhu.%hhu", (0x000000ff & address->ip4.s_addr), ((0x0000ff00 & address->ip4.s_addr) >> 8), + len = st_sprint(result, "%u.%u.%u", (0x000000ff & address->ip4.s_addr), ((0x0000ff00 & address->ip4.s_addr) >> 8), ((0x00ff0000 & address->ip4.s_addr) >> 16)); } // For IPv6 addresses use the first 64 bits, out of the total 128 bits available. The first 64 bits should contain the @@ -360,7 +360,7 @@ stringer_t * ip_standard(ip_t *address, stringer_t *output) { // Store the memory address where the output should be written. if (address->family == AF_INET) { - len = st_sprint(result, "%hhu.%hhu.%hhu.%hhu", (0x000000ff & address->ip4.s_addr), ((0x0000ff00 & address->ip4.s_addr) >> 8), + len = st_sprint(result, "%u.%u.%u.%u", (0x000000ff & address->ip4.s_addr), ((0x0000ff00 & address->ip4.s_addr) >> 8), ((0x00ff0000 & address->ip4.s_addr) >> 16), ((0xff000000 & address->ip4.s_addr) >> 24)); } else if (address->family == AF_INET6) { @@ -434,7 +434,7 @@ stringer_t * ip_reversed(ip_t *address, stringer_t *output) { // Store the memory address where the output should be written. if (address->family == AF_INET) { - len = st_sprint(result, "%hhu.%hhu.%hhu.%hhu", ((0xff000000 & address->ip4.s_addr) >> 24), ((0x00ff0000 & address->ip4.s_addr) >> 16), + len = st_sprint(result, "%u.%u.%u.%u", ((0xff000000 & address->ip4.s_addr) >> 24), ((0x00ff0000 & address->ip4.s_addr) >> 16), ((0x0000ff00 & address->ip4.s_addr) >> 8), (0x000000ff & address->ip4.s_addr)); } else if (address->family == AF_INET6) { diff --git a/src/providers/dime/signet/keys.c b/src/providers/dime/signet/keys.c index 8eab36dd..d7bede81 100644 --- a/src/providers/dime/signet/keys.c +++ b/src/providers/dime/signet/keys.c @@ -383,7 +383,7 @@ static int keys_generate(keys_type_t type, char **signet_pem, char **key_pem) { break; } - if (!(signet = dime_sgnt_signet_create(type))) { + if (!(signet = dime_sgnt_signet_create((signet_type_t)type))) { _free_ec_key(enc_key); _free_ed25519_key(sign_key); RET_ERROR_INT(ERR_UNSPEC, "could not create signet object"); diff --git a/src/providers/prime/messages/chunks/chunks.c b/src/providers/prime/messages/chunks/chunks.c index fce5f4b9..e0dd4238 100644 --- a/src/providers/prime/messages/chunks/chunks.c +++ b/src/providers/prime/messages/chunks/chunks.c @@ -10,10 +10,10 @@ int32_t chunk_buffer_size(stringer_t *chunk) { size_t len = 0; - uint8_t type = 0; uchr_t *data = NULL; int32_t result = -1; uint32_t big_endian_size = 0; + prime_message_chunk_type_t type = 0; if (st_empty_out(chunk, &data, &len) || len < 4 || (type = chunk_header_type(chunk)) == PRIME_CHUNK_INVALID) { log_pedantic("The chunk buffer is invalid."); @@ -40,10 +40,10 @@ int32_t chunk_buffer_size(stringer_t *chunk) { int32_t chunk_header_size(stringer_t *chunk) { size_t len = 0; - uint8_t type = 0; uchr_t *data = NULL; int32_t result = -1; uint32_t big_endian_size = 0; + prime_message_chunk_type_t type = 0; if (st_empty_out(chunk, &data, &len) || len < 4 || (type = chunk_header_type(chunk)) == PRIME_CHUNK_INVALID) { log_pedantic("The chunk buffer is invalid."); @@ -127,13 +127,14 @@ prime_message_chunk_type_t chunk_header_type(stringer_t *chunk) { int_t chunk_header_read(stringer_t *data, uint8_t *type, uint32_t *size, placer_t *chunk) { int32_t holder = 0; + prime_message_chunk_type_t local = 0; if (!data || !type || !size || !chunk) { log_pedantic("A NULL pointer was supplied to the PRIME chunk read function."); return 1; } - else if ((*type = chunk_header_type(data)) == PRIME_CHUNK_INVALID) { + else if ((local = chunk_header_type(data)) == PRIME_CHUNK_INVALID) { return -1; } @@ -142,9 +143,10 @@ int_t chunk_header_read(stringer_t *data, uint8_t *type, uint32_t *size, placer_ } // The chunk - *chunk = pl_init(st_data_get(data), holder + (*type < PRIME_SIGNATURE_TREE ? 4 : 1) + - (*type > PRIME_CHUNK_EPHEMERAL ? (slots_count(*type) * SECP256K1_SHARED_SECRET_LEN) : 0)); + *chunk = pl_init(st_data_get(data), holder + (local < PRIME_SIGNATURE_TREE ? 4 : 1) + + (local > PRIME_CHUNK_EPHEMERAL ? (slots_count(local) * SECP256K1_SHARED_SECRET_LEN) : 0)); *size = holder; + *type = local; // Bounds check, ensure the provided data buffer is large enough to hold the calculated length. if (pl_length_get(*chunk) > st_length_get(data)) { diff --git a/src/providers/prime/prime.h b/src/providers/prime/prime.h index 7079c0ce..6a07869b 100644 --- a/src/providers/prime/prime.h +++ b/src/providers/prime/prime.h @@ -93,7 +93,7 @@ typedef enum { PRIME_CHUNK_INVALID = -1, // Tracing - PRIME_CHUNK_TRACING = 0, /**< Tracing data. */ + PRIME_CHUNK_TRACING = 0, /**< Tracing data. */ // Envelope Block PRIME_CHUNK_EPHEMERAL = 1, /**< Ephemeral chunk. */ diff --git a/src/providers/prime/transposition/armored/pem.c b/src/providers/prime/transposition/armored/pem.c index ca124acd..9a490f48 100644 --- a/src/providers/prime/transposition/armored/pem.c +++ b/src/providers/prime/transposition/armored/pem.c @@ -125,7 +125,7 @@ stringer_t * prime_pem_wrap(stringer_t *object, stringer_t *output) { return NULL; } else if (!(begin = prime_pem_begin(type)) || !(end = prime_pem_end(type))) { - log_pedantic("The PRIME object type does not support the privacy enhanced message format. { magic = %hhu / type = %s }", + log_pedantic("The PRIME object type does not support the privacy enhanced message format. { magic = %hu / type = %s }", type, prime_object_type(type)); return NULL; } diff --git a/src/providers/prime/transposition/binary/fields.c b/src/providers/prime/transposition/binary/fields.c index 4c57f870..f6ac057a 100644 --- a/src/providers/prime/transposition/binary/fields.c +++ b/src/providers/prime/transposition/binary/fields.c @@ -101,10 +101,11 @@ size_t prime_field_size_max(uint16_t type, prime_field_type_t field) { stringer_t * prime_field_write(uint16_t type, prime_field_type_t field, size_t size, stringer_t *data, stringer_t *output) { + int_t size_len = 0; uchr_t *payload = NULL; stringer_t *result = NULL; uint32_t big_endian_size = 0; - size_t total = 0, size_len = 0, payload_len = 0; + size_t total = 0, payload_len = 0; /// TODO: Add undefined field support. if (field == 251) { diff --git a/src/web/portal/endpoint.c b/src/web/portal/endpoint.c index a0659b23..0441ed5b 100644 --- a/src/web/portal/endpoint.c +++ b/src/web/portal/endpoint.c @@ -446,7 +446,7 @@ void portal_endpoint_alert_acknowledge(connection_t *con) { json_error_t err; json_t *alerts; size_t count; - uint32_t transaction; + int64_t transaction; // Check the session state. Method has only one parameter, which may optionally be empty. if (!portal_validate_request (con, PORTAL_ENDPOINT_ERROR_ALERT_ACKNOWLEDGE, "alert.acknowledge", true, 0)) { |