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

Re: a problem with login and hostname



On Sat, Nov 11, 2000 at 06:27:51PM +0100, Thomas Poindessous wrote:
> I have change my hostname (it was 'null') to prom.epx.epita.fr.
> when I type hostname, it returns the right value but the login program
> gives me :
> 
> GNU 0.2 (prom.epx.epita.frines, init runs these programs,
> #and restarts them when th!0) (console)

This is a glibc bug. In libc/hurd/get-host.c, the returned buffer is not
null terminated if there is no newline in the file. A patch is below, I
didn't test it, but it's sort of obvious what is going wrong.

Mark, can you commit this or a patch with a similar effect?

Thanks,
Marcus

2000-11-13  Marcus Brinkmann <marcus@gnu.org>

	* hurd/get-host.c (_hurd_get_host_config): Fix possible buffer
	underrun and make sure the result is null terminated even if there
	is no trailing newline.

--- hurd/get-host.c.prior	Mon Nov 13 19:46:40 2000
+++ hurd/get-host.c	Mon Nov 13 20:00:34 2000
@@ -72,8 +72,15 @@
     }
     
   /* Remove newlines in case someone wrote the file by hand.  */
-  while (buf[nread - 1] == '\n')
+  while (buf[nread - 1] == '\n' && nread > 0)
     buf[--nread] = '\0';
+
+  /* Null-terminate the result if there is enough space.  */
+  if (nread < buflen)
+    buf[nread] = '\0';
+  else
+    if (buf[nread - 1] != '\0')
+      more = 1;
 
   if (more)
     /* If we didn't read the whole file, tell the caller to use a bigger


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



Reply to: