From 684374f353a687170f6d65b7c378719fc19b49cc Mon Sep 17 00:00:00 2001 From: Yves Rutschle Date: Sat, 11 May 2024 17:01:48 +0200 Subject: [PATCH] avoid useless strcpy (fix #440) --- systemd-sslh-generator.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/systemd-sslh-generator.c b/systemd-sslh-generator.c index bfddf84..1082a43 100644 --- a/systemd-sslh-generator.c +++ b/systemd-sslh-generator.c @@ -48,7 +48,7 @@ static const char "PartOf=sslh@%s.socket\n"; static char *resolve_listen(const char *hostname, const char *port) { - char *conn = malloc(strlen(hostname) + strlen(port) + 2); + char *conn = calloc(1, strlen(hostname) + strlen(port) + 2); CHECK_ALLOC(conn, "malloc") strcpy(conn, hostname); strcat(conn, ":"); @@ -86,12 +86,7 @@ static int get_listen_from_conf(const char *filename, char **listen[]) { config_setting_source_line(addr)); return -1; } else { - char *resolved_listen = resolve_listen(hostname, port); - - (*listen)[i] = malloc(strlen(resolved_listen)); - CHECK_ALLOC((*listen)[i], "malloc"); - strcpy((*listen)[i], resolved_listen); - free(resolved_listen); + (*listen)[i] = resolve_listen(hostname, port); } } }