From 6071f00ffe4c7f85171aef64dfc440dede8d511d Mon Sep 17 00:00:00 2001 From: Philip Paeps Date: Wed, 10 Jul 2019 22:36:14 +0000 Subject: [PATCH] telnet: fix minor style violation While here also fix a very unlikely NULL pointer dereference. Submitted by: Shawn Webb --- contrib/telnet/telnet/commands.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/contrib/telnet/telnet/commands.c b/contrib/telnet/telnet/commands.c index a2dcd26efd30..c6dc4ca064b7 100644 --- a/contrib/telnet/telnet/commands.c +++ b/contrib/telnet/telnet/commands.c @@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -1654,11 +1655,13 @@ 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'; - unsigned int buflen = strlen(hbuf) + strlen(cp2) + 1; + buflen = strlen(hbuf) + strlen(cp2) + 1; cp = (char *)malloc(sizeof(char)*buflen); + assert(cp != NULL); snprintf((char *)cp, buflen, "%s%s", hbuf, cp2); free(ep->value); ep->value = (unsigned char *)cp;