[comp.os.minix] bug in getgrent.c +FIX

jonathan@comp.vuw.ac.nz (Jonathan) (08/31/88)

Bug:
	getgrent.c assumes all lines in /etc/group have a colon as
	the last character.  It clobbers an arbitrary byte in memory
	containing a colon if they don't.

Symptom:
	Programs calling getgrid(3) (or friends) tend to lose their
	path.	Rsh(1) is a good candidate.

Repeat-By:
	Unshar the following test program and etc:group, move
	etc:group to /etc/group and run the program:

-------------------------test program-------------------------
echo x - getgr-test.c
sed '/^X/s///' > getgr-test.c << '/'
X/*
X * getgrtest.c - demonstrate amusing bug
X * with Minix 1.3b
X */
X
X#include <stdio.h>
X#include <grp.h>
Xextern char **environ, *getenv ();
X
Xpenv (str)
X    char *str;
X{
X    char **envp = environ;
X
X    printf("%s\n", str);
X    for (; (envp != 0) && (*envp != (char *) 0); envp++)
X	printf("%s\n", *envp);
X    printf("\n");
X
X}
X
X
Xmain ()
X{
X	register struct group *gr;
X	extern struct group *getgrgid();
X
X	penv("Environment before getgrid()");
X	gr = getgrgid(getgid());
X	penv("Environment after getgrid()");
X}
X
/
echo x - etc:group
sed '/^X/s///' > etc:group << '/'
Xwheel::0
Xdaemon::1
Xfoo::21
/
-------------------------End test program-------------------------

Fix-By:

	Apply the following shar'ed context diff:

echo x - getgrent.c.pat
sed '/^X/s///' > getgrent.c.pat << '/'
X*** /usr/src/minix/libsrc/getgrent.c	Thu Jul 14 04:27:22 1988
X--- ./getgrent.c	Mon Aug 29 17:13:23 1988
X***************
X*** 63,69 ****
X  
X  static skip_period () 
X  {
X!         while (*_buf != ':')
X  	        _buf++;
X          *_buf++ = '\0';
X  }
X--- 63,69 ----
X  
X  static skip_period () 
X  {
X!         while ((*_buf) && (*_buf != ':'))
X  	        _buf++;
X          *_buf++ = '\0';
X  }
/
-- 
-----------------------------------------------------------------------------
sane mailers: jonathan@comp.vuw.ac.nz |    Industrial democracy:
UUCP path: ...!uunet!vuwcomp!jonathan |           One factory, one vode!