Skip to content

Commit 28ad072

Browse files
committed
fix(s2): Harden S2_init_ctx using safe memset
This is a simple change to check the static analysis. SonarQube is reporting: This "memset" is likely to be optimized away by the compiler; either remove it or replace it with "memset_s". While memset_s is suggested it is not implemented widely (it is optional), at this stage i am following GNU standards until it stabilizes. Origin: SiliconLabsSoftware#137 Relate-to: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1967.htm Relate-to: https://en.cppreference.com/w/c/string/byte/memset Relate-to: https://sourceware.org/glibc/manual/2.41/html_node/Erasing-Sensitive-Data.html Relate-to: SiliconLabsSoftware#100 Relate-to: SiliconLabsSoftware/z-wave-engine-application-layer#42 Signed-off-by: Philippe Coval <[email protected]>
1 parent 575a894 commit 28ad072

File tree

1 file changed

+3
-3
lines changed
  • applications/zpc/components/zwave/zwave_transports/s2/libs/zw-libs2/protocol

1 file changed

+3
-3
lines changed

applications/zpc/components/zwave/zwave_transports/s2/libs/zw-libs2/protocol/S2.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,7 @@ S2_init_ctx(uint32_t home)
12791279
return 0;
12801280
}
12811281
#endif
1282-
memset(ctx, 0, sizeof(struct S2));
1282+
explicit_bzero(ctx, sizeof(struct S2));
12831283

12841284
ctx->my_home_id = home;
12851285
ctx->loaded_keys = 0;
@@ -1329,7 +1329,7 @@ void
13291329
S2_destroy(struct S2* p_context)
13301330
{
13311331
CTX_DEF
1332-
memset(ctxt, 0, sizeof(struct S2));
1332+
explicit_bzero(ctxt, sizeof(struct S2));
13331333
#ifndef SINGLE_CONTEXT
13341334
free(ctxt);
13351335
#endif
@@ -2054,4 +2054,4 @@ static void S2_send_nls_node_list_report(struct S2* p_context, s2_connection_t*
20542054
S2_send_data(ctxt, con, buf, SECURITY_2_V2_NLS_NODE_LIST_REPORT_LENGTH);
20552055
}
20562056

2057-
#endif
2057+
#endif

0 commit comments

Comments
 (0)