Skip to content

Instantly share code, notes, and snippets.

@lattera
Created July 11, 2019 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lattera/d49121a3e9a14b93868360edf32673f1 to your computer and use it in GitHub Desktop.
Save lattera/d49121a3e9a14b93868360edf32673f1 to your computer and use it in GitHub Desktop.
diff --git a/contrib/telnet/telnet/commands.c b/contrib/telnet/telnet/commands.c
index c6dc4ca064b7..79550e4e1daf 100644
--- a/contrib/telnet/telnet/commands.c
+++ b/contrib/telnet/telnet/commands.c
@@ -55,6 +55,7 @@ __FBSDID("$FreeBSD$");
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
+#include <sysexits.h>
#include <unistd.h>
#include <arpa/telnet.h>
@@ -1655,14 +1656,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';
- buflen = strlen(hbuf) + strlen(cp2) + 1;
- cp = (char *)malloc(sizeof(char)*buflen);
- assert(cp != NULL);
- snprintf((char *)cp, buflen, "%s%s", hbuf, cp2);
+ cp = NULL;
+ asprintf(&cp, "%s%s", hbuf, cp2);
+ if (cp == NULL)
+ errx(EX_OSERR, "Unable to allocate memory.");
free(ep->value);
ep->value = (unsigned char *)cp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment