forwarded message from mouring@etoh.eviladmin.org

Marcus Brinkmann
Mon, 23 Jul 2001 01:41:04 -0000

Hi,

I just looked in the mail archive to see what patch was posted
(http://marc.theaimsgroup.com/?l=openssh-unix-dev&m=99580473611227&w=2)

This piece of the patch is not good, because it is not defined if the
truncated name will be null terminated.  This can be fixed by null
terminating the reult no matter what, I think.

However, I really suggest to just put a get_host_name implementation in ssh,
that works on all systems and returns a malloced buffer.  This can then be
used everywhere were gethostname is used.

A good implementation is for example in GNU inetutils
(libinetutils/localhost.c)

Thanks,
Marcus

diff -ur openssh-2.9p2-/channels.c openssh-2.9p2/channels.c
--- openssh-2.9p2-/channels.c   Sat Mar 17 01:47:55 2001
+++ openssh-2.9p2/channels.c    Thu Jun 28 20:11:02 2001
@@ -1965,7 +1965,7 @@
        char strport[NI_MAXSERV];
        int gaierr, n, num_socks = 0, socks[NUM_SOCKS];
        char display[512];
-       char hostname[MAXHOSTNAMELEN];
+       char hostname[401];     /* we only use the first 400 bytes anyway*/

        for (display_number = x11_display_offset;
             display_number < MAX_DISPLAYS;
@@ -2037,7 +2037,8 @@
        }

        /* Set up a suitable value for the DISPLAY variable. */
-       if (gethostname(hostname, sizeof(hostname)) < 0)
+       if (gethostname(hostname, sizeof(hostname)) < 0
+           && errno != ENAMETOOLONG)
                fatal("gethostname: %.100s", strerror(errno));

 #ifdef IPADDR_IN_DISPLAY


--
`Rhubarb is no Egyptian god.' Debian http://www.debian.org brinkmd at
debian.org
Marcus Brinkmann              GNU    http://www.gnu.org    marcus at gnu.org
Marcus.Brinkmann at ruhr-uni-bochum.de