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

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



Marcus Brinkmann <Marcus.Brinkmann@ruhr-uni-bochum.de> writes:

> 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.

You are right. Me bad! I read "The returned name is null-terminated"
in the standard, and missed the "except" clause.

Replacement patch:

diff -u openssh-2.9p2/channels.c~ openssh-2.9p2/channels.c
--- openssh-2.9p2/channels.c~	Mon Jul 23 13:50:54 2001
+++ openssh-2.9p2/channels.c	Mon Jul 23 13:50:54 2001
@@ -2159,7 +2159,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;
@@ -2232,7 +2232,10 @@
 
 	/* Set up a suitable value for the DISPLAY variable. */
 	if (gethostname(hostname, sizeof(hostname)) < 0)
-		fatal("gethostname: %.100s", strerror(errno));
+		if (errno == ENAMETOOLONG)
+			hostname[sizeof(hostname) - 1] = 0;
+		else
+			fatal("gethostname: %.100s", strerror(errno));
 
 #ifdef IPADDR_IN_DISPLAY
 	/*
-- 
Robbe

Attachment: signature.ng
Description: PGP signature


Reply to: