Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: clang-tidy null deref and undefined mod #4436

Merged
merged 9 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion crypto/s2n_pkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ int s2n_pkey_match(const struct s2n_pkey *pub_key, const struct s2n_pkey *priv_k

int s2n_pkey_free(struct s2n_pkey *key)
{
if (key != NULL && key->free != NULL) {
if (key == NULL) {
return S2N_SUCCESS;
}

if (key->free != NULL) {
POSIX_GUARD(key->free(key));
}

Expand Down
8 changes: 6 additions & 2 deletions stuffer/s2n_stuffer_network_order.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@
/* Writes length bytes of input to stuffer, in network order, starting from the smallest byte of input. */
int s2n_stuffer_write_network_order(struct s2n_stuffer *stuffer, const uint64_t input, const uint8_t length)
{
if (length == 0) {
return S2N_SUCCESS;
}
POSIX_ENSURE_REF(stuffer);
POSIX_ENSURE(length <= sizeof(input), S2N_ERR_SAFETY);
POSIX_GUARD(s2n_stuffer_skip_write(stuffer, length));
uint8_t *data = (stuffer->blob.data) ? (stuffer->blob.data + stuffer->write_cursor - length) : NULL;

POSIX_ENSURE_REF(stuffer->blob.data);
uint8_t *data = stuffer->blob.data + stuffer->write_cursor - length;
for (int i = 0; i < length; i++) {
S2N_INVARIANT(i <= length);
uint8_t shift = (length - i - 1) * CHAR_BIT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ PROJECT_SOURCES += $(SRCDIR)/utils/s2n_mem.c
PROJECT_SOURCES += $(SRCDIR)/utils/s2n_result.c
PROJECT_SOURCES += $(SRCDIR)/utils/s2n_safety.c

UNWINDSET += s2n_stuffer_write_network_order.4:9
UNWINDSET += s2n_stuffer_write_network_order.10:9

# We abstract this function because manual inspection demonstrates it is unreachable.
REMOVE_FUNCTION_BODY += __CPROVER_file_local_s2n_mem_c_s2n_mem_cleanup_impl
Expand Down
2 changes: 1 addition & 1 deletion tests/cbmc/proofs/s2n_dh_params_to_p_g_Ys/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ REMOVE_FUNCTION_BODY += s2n_free
REMOVE_FUNCTION_BODY += s2n_realloc
REMOVE_FUNCTION_BODY += s2n_stuffer_wipe

UNWINDSET += s2n_stuffer_write_network_order.4:9
UNWINDSET += s2n_stuffer_write_network_order.10:9

include ../Makefile.common
2 changes: 1 addition & 1 deletion tests/cbmc/proofs/s2n_stuffer_write_network_order/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ REMOVE_FUNCTION_BODY += __CPROVER_file_local_s2n_mem_c_s2n_mem_cleanup_impl
REMOVE_FUNCTION_BODY += s2n_blob_slice
REMOVE_FUNCTION_BODY += s2n_stuffer_wipe

UNWINDSET += s2n_stuffer_write_network_order.4:9
UNWINDSET += s2n_stuffer_write_network_order.10:9
UNWINDSET += s2n_stuffer_write_network_order_harness.0:9

include ../Makefile.common
9 changes: 1 addition & 8 deletions tests/cbmc/proofs/s2n_stuffer_write_reservation/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@ REMOVE_FUNCTION_BODY += s2n_stuffer_wipe
REMOVE_FUNCTION_BODY += s2n_stuffer_wipe_n
REMOVE_FUNCTION_BODY += __CPROVER_file_local_s2n_mem_c_s2n_mem_cleanup_impl

UNWINDSET += s2n_stuffer_write_network_order.0:$(MAX_WRITE_NETWORK_ORDER)
UNWINDSET += s2n_stuffer_write_network_order.1:$(MAX_WRITE_NETWORK_ORDER)
UNWINDSET += s2n_stuffer_write_network_order.2:$(MAX_WRITE_NETWORK_ORDER)
UNWINDSET += s2n_stuffer_write_network_order.3:$(MAX_WRITE_NETWORK_ORDER)
UNWINDSET += s2n_stuffer_write_network_order.4:$(MAX_WRITE_NETWORK_ORDER)
UNWINDSET += s2n_stuffer_write_network_order.5:$(MAX_WRITE_NETWORK_ORDER)
UNWINDSET += s2n_stuffer_write_network_order.6:$(MAX_WRITE_NETWORK_ORDER)
UNWINDSET += s2n_stuffer_write_network_order.7:$(MAX_WRITE_NETWORK_ORDER)
UNWINDSET += s2n_stuffer_write_network_order.10:$(MAX_WRITE_NETWORK_ORDER)

include ../Makefile.common
2 changes: 1 addition & 1 deletion tests/cbmc/proofs/s2n_stuffer_write_uint16/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ PROJECT_SOURCES += $(SRCDIR)/utils/s2n_result.c
REMOVE_FUNCTION_BODY += s2n_blob_slice
REMOVE_FUNCTION_BODY += s2n_stuffer_wipe

UNWINDSET += s2n_stuffer_write_network_order.4:$(shell echo $$((1 + $(SIZEOF_UINT16))))
UNWINDSET += s2n_stuffer_write_network_order.10:$(shell echo $$((1 + $(SIZEOF_UINT16))))

include ../Makefile.common
2 changes: 1 addition & 1 deletion tests/cbmc/proofs/s2n_stuffer_write_uint24/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ PROJECT_SOURCES += $(SRCDIR)/utils/s2n_result.c
REMOVE_FUNCTION_BODY += s2n_blob_slice
REMOVE_FUNCTION_BODY += s2n_stuffer_wipe

UNWINDSET += s2n_stuffer_write_network_order.4:$(shell echo $$((1 + $(SIZEOF_UINT24))))
UNWINDSET += s2n_stuffer_write_network_order.10:$(shell echo $$((1 + $(SIZEOF_UINT24))))

include ../Makefile.common
2 changes: 1 addition & 1 deletion tests/cbmc/proofs/s2n_stuffer_write_uint32/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ PROJECT_SOURCES += $(SRCDIR)/utils/s2n_result.c
REMOVE_FUNCTION_BODY += s2n_blob_slice
REMOVE_FUNCTION_BODY += s2n_stuffer_wipe

UNWINDSET += s2n_stuffer_write_network_order.4:$(shell echo $$((1 + $(SIZEOF_UINT32))))
UNWINDSET += s2n_stuffer_write_network_order.10:$(shell echo $$((1 + $(SIZEOF_UINT32))))

include ../Makefile.common
2 changes: 1 addition & 1 deletion tests/cbmc/proofs/s2n_stuffer_write_uint64/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ PROJECT_SOURCES += $(SRCDIR)/utils/s2n_result.c
REMOVE_FUNCTION_BODY += s2n_blob_slice
REMOVE_FUNCTION_BODY += s2n_stuffer_wipe

UNWINDSET += s2n_stuffer_write_network_order.4:$(shell echo $$((1 + $(SIZEOF_UINT64))))
UNWINDSET += s2n_stuffer_write_network_order.10:$(shell echo $$((1 + $(SIZEOF_UINT64))))

include ../Makefile.common
9 changes: 1 addition & 8 deletions tests/cbmc/proofs/s2n_stuffer_write_vector_size/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ REMOVE_FUNCTION_BODY += s2n_stuffer_resize
REMOVE_FUNCTION_BODY += s2n_stuffer_wipe_n
REMOVE_FUNCTION_BODY += __CPROVER_file_local_s2n_mem_c_s2n_mem_cleanup_impl

UNWINDSET += s2n_stuffer_write_network_order.0:$(MAX_WRITE_NETWORK_ORDER)
UNWINDSET += s2n_stuffer_write_network_order.1:$(MAX_WRITE_NETWORK_ORDER)
UNWINDSET += s2n_stuffer_write_network_order.2:$(MAX_WRITE_NETWORK_ORDER)
UNWINDSET += s2n_stuffer_write_network_order.3:$(MAX_WRITE_NETWORK_ORDER)
UNWINDSET += s2n_stuffer_write_network_order.4:$(MAX_WRITE_NETWORK_ORDER)
UNWINDSET += s2n_stuffer_write_network_order.5:$(MAX_WRITE_NETWORK_ORDER)
UNWINDSET += s2n_stuffer_write_network_order.6:$(MAX_WRITE_NETWORK_ORDER)
UNWINDSET += s2n_stuffer_write_network_order.7:$(MAX_WRITE_NETWORK_ORDER)
UNWINDSET += s2n_stuffer_write_network_order.10:$(MAX_WRITE_NETWORK_ORDER)

include ../Makefile.common
2 changes: 1 addition & 1 deletion tls/s2n_security_rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ S2N_CLEANUP_RESULT s2n_security_rule_result_free(struct s2n_security_rule_result
{
if (result) {
RESULT_GUARD_POSIX(s2n_stuffer_free(&result->output));
*result = (struct s2n_security_rule_result){ 0 };
}
*result = (struct s2n_security_rule_result){ 0 };
return S2N_RESULT_OK;
}
1 change: 1 addition & 0 deletions utils/s2n_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
static S2N_RESULT s2n_map_slot(const struct s2n_map *map, struct s2n_blob *key, uint32_t *slot)
{
RESULT_ENSURE_REF(map);
RESULT_ENSURE(map->capacity != 0, S2N_ERR_SAFETY);
union {
uint8_t u8[32];
uint32_t u32[8];
Expand Down
Loading