Aittvax.187
net.bugs.v7,net.bugs.4bsd
utzoo!decvax!ittvax!swatt
Fri Jan 8 21:32:41 1982
pwd bug
Fri Jan 8 21:22:38 EST 1982 (ittvax!freb)
[ ] The command "pwd" will do strange things if any of the
directories above the present one lack execute permission. It
will print some random string, but not exit with an error
status. Programs which do 'popen ("pwd", "r")' in order to get
the current directory can get fooled.
The reason is in several places "pwd" never checks the return
status on certain system calls.
The fix is:
===============================================================
cp /usr/src/cmd/pwd.c /tmp/upd.$$.tmp ; chmod +w /tmp/upd.$$.tmp
ed - /tmp/upd.$$.tmp <<\!XXFUNNYXX ERRNO; DOTDOT, STATIC , . /USR/SRC/CMD/PWD.C /* EXIT ; Q !XXFUNNYXX W CHAR %S\":%S\N", { CANNOT STAT \ } (STDERR, 1C (CHDIR(DOTDOT)) @@@ *SYS_ERRLIST[]; CANNOT /TMP/UPD.$$.TMP DOT, FPRINTF &D)) (1); (STAT(DOT, TERRIBLE ERROR: CANNOT STAT \ 30C 22C OPEN CHECK */ DIFF \"%S\":%S\N", FPRINTF(STDERR,"PWD: (STAT("/", IF *SCCSID="@(#)pwd.c 4.2 (ITT) 01/08/82" SYS_ERRLIST[ERRNO]); 17A 34C 26C CANNOT STAT %S:%S\N EXTERN /\"!:%S\N",>/tmp/upd.$$.dif
if cmp - /tmp/upd.$$.dif <<\!XXFUNNYXX STATIC ; < CHAR 1C1 --- *SCCSID="@(#)pwd.c 4.1 (Berkeley) 10/1/80"> static char *sccsid = "@(#)pwd.c 4.2 (ITT) 01/08/82";
17a18,20
> extern errno;
> extern char *sys_errlist[];
>
22c25,29
if (stat("/", &d)) {
> fprintf (stderr, "TERRIBLE ERROR: cannot stat \"/\"!:%s\n",
> sys_errlist[errno]);
> exit (1);
> }
26c33,37
if (stat(dot, &d)) {
> fprintf (stderr, "Cannot stat \"%s\":%s\n",
> dot, sys_errlist[errno]);
> exit (1);
> }
30c41,42
fprintf(stderr,"pwd: cannot open \"%s\":%s\n",
> dotdot, sys_errlist[errno]);
34c46,51
/* @@@ check */
> if (chdir(dotdot)) {
> fprintf (stderr, "Cannot stat %s:%s\n", dotdot,
> sys_errlist[errno]);
> exit (1);
> }
!xxFUNNYxx
then
: 'compare equal, ok'
rm -f pwd.c
cp /tmp/upd.$$.tmp pwd.c ; chmod a-w pwd.c
else
echo "Old source file not same version;" \
"use diff listings by hand"
fi
rm -f /tmp/upd.$$.tmp /tmp/upd.$$.dif
===============================================================
-----------------------------------------------------------------
gopher://quux.org/ conversion by John Goerzen <
[email protected]>
of
http://communication.ucsd.edu/A-News/
This Usenet Oldnews Archive
article may be copied and distributed freely, provided:
1. There is no money collected for the text(s) of the articles.
2. The following notice remains appended to each copy:
The Usenet Oldnews Archive: Compilation Copyright (C) 1981, 1996
Bruce Jones, Henry Spencer, David Wiseman.