[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: forwarded message from mouring@etoh.eviladmin.org


I just looked in the mail archive to see what patch was posted

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


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));


`Rhubarb is no Egyptian god.' Debian http://www.debian.org brinkmd@debian.org
Marcus Brinkmann              GNU    http://www.gnu.org    marcus@gnu.org

Reply to: