From 90375397d4ae382200e1346f8dc54040e714c1ca Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Mon, 14 Aug 2023 09:02:42 +0200 Subject: [PATCH] Minor changes to memset() call Call calloc() instead of malloc()/memset(). --- src/ipv4.c | 14 +++++++------- src/tunnel.c | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/ipv4.c b/src/ipv4.c index 0ff91a6d..698bf108 100644 --- a/src/ipv4.c +++ b/src/ipv4.c @@ -116,7 +116,7 @@ static inline void route_destroy(struct rtentry *route) static int ipv4_get_route(struct rtentry *route) { size_t buffer_size = IPV4_GET_ROUTE_BUFFER_CHUNK_SIZE; - char *buffer = malloc(buffer_size); + char *buffer; char *realloc_buffer; int err = 0; char *start, *line; @@ -124,11 +124,6 @@ static int ipv4_get_route(struct rtentry *route) uint32_t rtdest, rtmask, rtgtw; int rtfound = 0; - if (!buffer) { - err = ERR_IPV4_SEE_ERRNO; - goto end; - } - /* * initialize the buffer with zeroes, aiming to address the * coverity issue "TAINTED_SCALAR passed to a tainted sink" @@ -148,7 +143,12 @@ static int ipv4_get_route(struct rtentry *route) * that there is a delimiting '\0' character by proper * initialization. We ensure this also when growing the buffer. */ - memset(buffer, '\0', IPV4_GET_ROUTE_BUFFER_CHUNK_SIZE); + buffer = calloc(1, buffer_size); + if (!buffer) { + err = ERR_IPV4_SEE_ERRNO; + goto end; + } + log_debug("ip route show %s\n", ipv4_show_route(route)); // store what we are looking for diff --git a/src/tunnel.c b/src/tunnel.c index 062edf75..fb877c95 100644 --- a/src/tunnel.c +++ b/src/tunnel.c @@ -808,7 +808,7 @@ static int tcp_connect(struct tunnel *tunnel) log_debug("server_addr: %s\n", inet_ntoa(server.sin_addr)); log_debug("server_port: %u\n", ntohs(server.sin_port)); server.sin_family = AF_INET; - memset(&(server.sin_zero), '\0', 8); + memset(&(server.sin_zero), 0, sizeof(server.sin_zero)); log_debug("gateway_ip: %s\n", inet_ntoa(tunnel->config->gateway_ip)); log_debug("gateway_port: %u\n", tunnel->config->gateway_port); @@ -840,7 +840,7 @@ static int tcp_connect(struct tunnel *tunnel) // be careful not to fetch too many bytes at once const char *response = NULL; - memset(&(request), '\0', sizeof(request)); + memset(&(request), 0, sizeof(request)); for (int j = 0; response == NULL; j++) { if (j >= ARRAY_SIZE(request) - 1) { log_error("Proxy response is unexpectedly large and cannot fit in the %lu-bytes buffer.\n",