From 1a617d0e1b5f365c4f5b35fc8012d0d668902ea5 Mon Sep 17 00:00:00 2001 From: emaste 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 c6dc4ca064b..8b7c6595b90 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; } -- 2.45.0