From 0555e0989fc4f0bfedd2da0ad65472b7226bb9ca Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Wed, 13 Nov 2019 08:14:48 +0100 Subject: [PATCH] Fix suspicius code for allocating a sockaddr_un to a sockaddr ptr Remarked on by Coverity Scan. Signed-off-by: Joachim Nilsson --- src/socket.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/socket.c b/src/socket.c index fd13fac..12a49af 100644 --- a/src/socket.c +++ b/src/socket.c @@ -77,10 +77,13 @@ int socket_register(int sd, struct addrinfo *ai, void (*cb)(int, void *), void * goto err; if (ai) { - entry->ai.ai_addr = calloc(1, sizeof(struct sockaddr_un)); - if (!entry->ai.ai_addr) + struct sockaddr_un *sun; + + sun = calloc(1, sizeof(struct sockaddr_un)); + if (!sun) goto eaddr; + entry->ai.ai_addr = (struct sockaddr *)sun; entry->ai = *ai; *entry->ai.ai_addr = *ai->ai_addr; }