Created
July 10, 2019 22:28
-
-
Save lattera/579685c0252673c3ad92d2536c3486c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <sys/socket.h> | |
#include <netinet/in.h> | |
+#include <assert.h> | |
#include <ctype.h> | |
#include <err.h> | |
#include <errno.h> | |
@@ -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; |
Because the existing code already used malloc + snprintf?
And this is telnet, which arguably should be rf -rf
ed? ;)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Any reason to not just use asprintf() instead of malloc + sprintf?