Replace memset() with mbedtls_platform_memset()
Steps:
1. sed -i 's/\bmemset(\([^)]\)/mbedtls_platform_memset(\1/g' library/*.c tinycrypt/*.c include/mbedtls/*.h scripts/data_files/*.fmt
2. Manually edit library/platform_util.c to revert to memset() in the
implementations of mbedtls_platform_memset() and mbedtls_platform_memcpy()
3. egrep -n '\<memset\>' library/*.c include/mbedtls/*.h tinycrypt/*.c
The remaining occurrences are in three categories:
a. From point 2 above.
b. In comments.
c. In the initialisation of memset_func, to be changed in a future commit.
diff --git a/library/net_sockets.c b/library/net_sockets.c
index 8d6c788..58244e5 100644
--- a/library/net_sockets.c
+++ b/library/net_sockets.c
@@ -154,7 +154,7 @@
return( ret );
/* Do name resolution with both IPv6 and IPv4 */
- memset( &hints, 0, sizeof( hints ) );
+ mbedtls_platform_memset( &hints, 0, sizeof( hints ) );
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = proto == MBEDTLS_NET_PROTO_UDP ? SOCK_DGRAM : SOCK_STREAM;
hints.ai_protocol = proto == MBEDTLS_NET_PROTO_UDP ? IPPROTO_UDP : IPPROTO_TCP;
@@ -201,7 +201,7 @@
return( ret );
/* Bind to IPv6 and/or IPv4, but only in the desired protocol */
- memset( &hints, 0, sizeof( hints ) );
+ mbedtls_platform_memset( &hints, 0, sizeof( hints ) );
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = proto == MBEDTLS_NET_PROTO_UDP ? SOCK_DGRAM : SOCK_STREAM;
hints.ai_protocol = proto == MBEDTLS_NET_PROTO_UDP ? IPPROTO_UDP : IPPROTO_TCP;
@@ -471,8 +471,8 @@
/* Ensure that memory sanitizers consider read_fds and write_fds as
* initialized even on platforms such as Glibc/x86_64 where FD_ZERO
* is implemented in assembly. */
- memset( &read_fds, 0, sizeof( read_fds ) );
- memset( &write_fds, 0, sizeof( write_fds ) );
+ mbedtls_platform_memset( &read_fds, 0, sizeof( read_fds ) );
+ mbedtls_platform_memset( &write_fds, 0, sizeof( write_fds ) );
#endif
#endif