[2240] in Kerberos-V5-bugs
krb5b7: telnet: canonify host name when doing XDISPLOC
daemon@ATHENA.MIT.EDU (Jonathan I. Kamens)
Tue Sep 17 17:12:59 1996
Date: Tue, 17 Sep 1996 17:12:17 -0400
From: "Jonathan I. Kamens" <jik@jik.tiac.net>
To: krb5-bugs@MIT.EDU, kerberos@MIT.EDU
When changing DISPLAY values of the form ":x.x" or "unix:x.x" to
"hostname:x.x" in order to send them to the remote host using the
XDISPLOC option, telnet should call gethostbyname() to fully qualify
the host name, so that it'll be valid even when connecting to a host
in a different domain.
Also, telnet should check the return value of gethostname().
Here's a diff:
--- telnet/commands.c 1996/09/17 19:56:23 1.4
+++ telnet/commands.c 1996/09/17 19:57:31 1.5
@@ -1719,13 +1719,21 @@
|| (strncmp((char *)ep->value, "unix:", 5) == 0))) {
char hbuf[256+1];
char *cp2 = strchr((char *)ep->value, ':');
+
+ if (gethostname(hbuf, 256) == 0) {
+ struct hostent *host;
- gethostname(hbuf, 256);
- hbuf[256] = '\0';
- cp = (char *)malloc(strlen(hbuf) + strlen(cp2) + 1);
- sprintf((char *)cp, "%s%s", hbuf, cp2);
- free(ep->value);
- ep->value = (unsigned char *)cp;
+ hbuf[256] = '\0';
+ host = gethostbyname(hbuf);
+ if (host) {
+ strncpy(hbuf, host->h_name, sizeof(hbuf));
+ hbuf[256] = '\0';
+ }
+ cp = (char *)malloc(strlen(hbuf) + strlen(cp2) + 1);
+ sprintf((char *)cp, "%s%s", hbuf, cp2);
+ free(ep->value);
+ ep->value = (unsigned char *)cp;
+ }
}
/*
* If USER is not defined, but LOGNAME is, then add