home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Bug_Fixes / Net.v7bugs / 0059 < prev    next >
Encoding:
Text File  |  1982-01-09  |  2.5 KB  |  109 lines

  1. Aittvax.187
  2. net.bugs.v7,net.bugs.4bsd
  3. utzoo!decvax!ittvax!swatt
  4. Fri Jan  8 21:32:41 1982
  5. pwd bug
  6. Fri Jan  8 21:22:38 EST 1982 (ittvax!freb)
  7.  
  8. [ ]    The command "pwd" will do strange things if any of the
  9.     directories above the present one lack execute permission.  It
  10.     will print some random string, but not exit with an error
  11.     status.  Programs which do 'popen ("pwd", "r")' in order to get
  12.     the current directory can get fooled.
  13.  
  14.     The reason is in several places "pwd" never checks the return
  15.     status on certain system calls.
  16.  
  17.     The fix is:
  18.     ===============================================================
  19.     cp /usr/src/cmd/pwd.c /tmp/upd.$$.tmp ; chmod +w /tmp/upd.$$.tmp
  20.     ed - /tmp/upd.$$.tmp <<\!xxFUNNYxx
  21.     34c
  22.             /* @@@ check */
  23.             if (chdir(dotdot)) {
  24.                 fprintf (stderr, "Cannot stat %s:%s\n", dotdot,
  25.                      sys_errlist[errno]);
  26.                 exit (1);
  27.             }
  28.     .
  29.     30c
  30.                 fprintf(stderr,"pwd: cannot open \"%s\":%s\n",
  31.                     dotdot, sys_errlist[errno]);
  32.     .
  33.     26c
  34.             if (stat(dot, &d)) {
  35.                 fprintf (stderr, "Cannot stat \"%s\":%s\n",
  36.                      dot, sys_errlist[errno]);
  37.                 exit (1);
  38.             }
  39.     .
  40.     22c
  41.         if (stat("/", &d)) {
  42.             fprintf (stderr, "TERRIBLE ERROR: cannot stat \"/\"!:%s\n",
  43.                  sys_errlist[errno]);
  44.             exit (1);
  45.         }
  46.     .
  47.     17a
  48.     extern    errno;
  49.     extern    char *sys_errlist[];
  50.  
  51.     .
  52.     1c
  53.     static char *sccsid = "@(#)pwd.c    4.2 (ITT) 01/08/82";
  54.     .
  55.     w
  56.     q
  57.     !xxFUNNYxx
  58.     diff /usr/src/cmd/pwd.c /tmp/upd.$$.tmp >/tmp/upd.$$.dif
  59.     if cmp - /tmp/upd.$$.dif <<\!xxFUNNYxx
  60.     1c1
  61.     < static char *sccsid = "@(#)pwd.c    4.1 (Berkeley) 10/1/80";
  62.     ---
  63.     > static char *sccsid = "@(#)pwd.c    4.2 (ITT) 01/08/82";
  64.     17a18,20
  65.     > extern    errno;
  66.     > extern    char *sys_errlist[];
  67.     > 
  68.     22c25,29
  69.     <     stat("/", &d);
  70.     ---
  71.     >     if (stat("/", &d)) {
  72.     >         fprintf (stderr, "TERRIBLE ERROR: cannot stat \"/\"!:%s\n",
  73.     >              sys_errlist[errno]);
  74.     >         exit (1);
  75.     >     }
  76.     26c33,37
  77.     <         stat(dot, &d);
  78.     ---
  79.     >         if (stat(dot, &d)) {
  80.     >             fprintf (stderr, "Cannot stat \"%s\":%s\n",
  81.     >                  dot, sys_errlist[errno]);
  82.     >             exit (1);
  83.     >         }
  84.     30c41,42
  85.     <             fprintf(stderr,"pwd: cannot open ..\n");
  86.     ---
  87.     >             fprintf(stderr,"pwd: cannot open \"%s\":%s\n",
  88.     >                 dotdot, sys_errlist[errno]);
  89.     34c46,51
  90.     <         chdir(dotdot);
  91.     ---
  92.     >         /* @@@ check */
  93.     >         if (chdir(dotdot)) {
  94.     >             fprintf (stderr, "Cannot stat %s:%s\n", dotdot,
  95.     >                  sys_errlist[errno]);
  96.     >             exit (1);
  97.     >         }
  98.     !xxFUNNYxx
  99.     then
  100.         : 'compare equal, ok'
  101.         rm -f pwd.c
  102.         cp /tmp/upd.$$.tmp pwd.c ; chmod a-w pwd.c
  103.     else
  104.         echo "Old source file not same version;" \
  105.             "use diff listings by hand"
  106.     fi
  107.     rm -f /tmp/upd.$$.tmp /tmp/upd.$$.dif
  108.     ===============================================================
  109.