bug in newgrp.c

utzoo!decvax!harpo!seismo!uwvax!solomon utzoo!decvax!harpo!seismo!uwvax!solomon
Fri Feb 25 10:00:42 AEST 1983


There is a bug in newgrp.c (at least in the version that comes with 4.1BSD).
When doing the "exec" of a new shell, it tries to give the "-i" flag.
However, since it gives it as the second argument to exec, it becomes
argument 0 to the shell, which makes the forked shell to think it's a
login shell, leading to all kinds of strange behavior (for example, it
will fail if you have any stopped jobs).  I'm not sure why newgrp is
trying to supply the "-i" flag anyhow; "su" doesn't use it.
The fix is extremely trivial.
NB:  This fix has only been tested on 4.1BSD and only with csh.

The version of newgrp is

	static char *sccsid = "@(#)newgrp.c	4.1 (Berkeley) 10/1/80";

The changes are

	*** newgrp.c.old	Fri Feb 25 09:48:07 1983
	--- newgrp.c.new	Fri Feb 25 09:52:12 1983
	***************
	*** 45,51
		setuid(getuid());
		for (i=3; i<15; i++)
			close(i);
	! 	execl((pwd->pw_shell[0]?pwd->pw_shell:"/bin/sh"), "-i", 0);
		printf("No shell!\n");
		exit(0);
	  }

	--- 45,51 -----
		setuid(getuid());
		for (i=3; i<15; i++)
			close(i);
	! 	execl((pwd->pw_shell[0]?pwd->pw_shell:"/bin/sh"), "newgrp", 0);
		printf("No shell!\n");
		exit(0);
	  }



More information about the Comp.bugs.4bsd.ucb-fixes mailing list