From deffed6ea22597d17d6611cf83ae80d40396a884 Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Thu, 1 Aug 2019 13:46:04 +0000 Subject: [PATCH] telnet: use asprintf for r349890 change Suggested by: imp MFC after: 3 weeks Sponsored by: The FreeBSD Foundation --- contrib/telnet/telnet/commands.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/contrib/telnet/telnet/commands.c b/contrib/telnet/telnet/commands.c index c6dc4ca064b7..8b7c6595b906 100644 --- a/contrib/telnet/telnet/commands.c +++ b/contrib/telnet/telnet/commands.c @@ -1655,14 +1655,11 @@ env_init(void) || (strncmp((char *)ep->value, "unix:", 5) == 0))) { char hbuf[256+1]; char *cp2 = strchr((char *)ep->value, ':'); - size_t buflen; gethostname(hbuf, sizeof(hbuf)); hbuf[sizeof(hbuf)-1] = '\0'; - buflen = strlen(hbuf) + strlen(cp2) + 1; - cp = (char *)malloc(sizeof(char)*buflen); + asprintf(&cp, "%s%s", hbuf, cp2); assert(cp != NULL); - snprintf((char *)cp, buflen, "%s%s", hbuf, cp2); free(ep->value); ep->value = (unsigned char *)cp; }