edwin@ruuinf.cs.ruu.nl (Edwin Kremer) (03/28/90)
We came across a bug in the "getcwd" library function in ST-MINIX 1.5.5,
it might also occur in the PC version (actually, we're almost sure because
the PC<->ST POSIX libraries are equal, aren't they?).
As it turns out, getcwd() does *not* skip unused directory slots, e.g.
entries that are no longer in use and have inode number 0 assigned.
Ok, here's an example (some imaginary directory dump)
d_ino d_name
============================
1 .
1 ..
123 valid_file1
0 invalid_file
45 valid_file2
getcwd() loops through this directory to lookup an inode number; for
every entry, it does a "stat()" system call on ``d_name''. On the
fourth entry it stats "invalid_file" (inode 0 ==> free slot): stat()
fails and getcwd() returns NULL.
E.g. "/bin/pwd" now complains: "Can't search some directory on the path".
The following (unofficial!!) patch fixes this problem.
Good luck,
Bart Muijzer <bartm@cs.ruu.nl>
Edwin Kremer <edwin@cs.ruu.nl>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*** getcwd.c.old Tue Mar 27 23:22:44 1990
--- getcwd.c Tue Mar 27 23:14:41 1990
***************
*** 52,57 ****
--- 52,61 ----
/* Search the parent directory for the current entry */
if ((fd = open(".", O_RDONLY)) == -1) return((char *)NULL);
while (!found && read(fd, (char *)&d, DIRECT_SIZE) == DIRECT_SIZE) {
+ if ( d.d_ino == 0 )
+ /* skip free (unused) directory slots */
+ continue;
if (same_device) {
if (current.st_ino == d.d_ino) found = 1;
} else {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
Edwin Kremer (SysAdm), Dept. of Computer Science, Utrecht University
Padualaan 14, P.O. Box 80.089, 3508 TB Utrecht, The Netherlands
Telephone: +31-30-534104 | UUCP: ...!uunet!mcsun!hp4nl!ruuinf!edwin
Telefax : +31-30-513791 | Email: edwin@cs.ruu.nl [131.211.80.5]
hall@cod.NOSC.MIL (Robert R. Hall) (03/29/90)
I tried to apply this patch to lib/posix/getcwd.c only to have patch reject it with a core dump message Since it wasn't that big I edited in the patch manually then I used cdiff to get my version of the cdiff patch and found the line count differ (see enclosed cdiff) I then edited the posted cdiff with the 61 number changed to a 60 and patch now responded with hunk sucessfull. Edwin Kremer would you please check you cdiff command and find why it can't count correctly? Robert R. Hall (hall@nosc.mil) *** p2 Wed Mar 28 07:46:09 1990 --- p1 Wed Mar 28 07:43:01 1990 *************** *** 2,8 **** --- getcwd.c Tue Mar 27 23:14:41 1990 *************** *** 52,57 **** ! --- 52,61 ---- /* Search the parent directory for the current entry */ if ((fd = open(".", O_RDONLY)) == -1) return((char *)NULL); while (!found && read(fd, (char *)&d, DIRECT_SIZE) == DIRECT_SIZE) { --- 2,8 ---- --- getcwd.c Tue Mar 27 23:14:41 1990 *************** *** 52,57 **** ! --- 52,60 ---- /* Search the parent directory for the current entry */ if ((fd = open(".", O_RDONLY)) == -1) return((char *)NULL); while (!found && read(fd, (char *)&d, DIRECT_SIZE) == DIRECT_SIZE) {
edwin@praxis.cs.ruu.nl (Edwin Kremer) (03/29/90)
In article <1842@cod.NOSC.MIL> hall@cod.NOSC.MIL (Robert R. Hall) writes: | I tried to apply this patch to lib/posix/getcwd.c | only to have patch reject it with a core dump message | ... | Edwin Kremer would you please check you cdiff command and | find why it can't count correctly? Oh boy, *am* I stupid! My cdiff counts ok, but I goofed... This is what I did: my patch actually *was* 4 lines; a had an extra trailing blank line that I decided *not* to add after all. So, I edited my patch, deleted the extra line AND forgot to change the linenumbers... I guess this is becoming the First Law of Patching: "Never patch a patch." My apologies to all of you that had a core dump... I think Robert has made very clear how to fix it, so there's most probably no need for a repost (the patch is indeed very small). Anyway, if you want a repost, let me know. --[ Edwin ]-- -- Edwin Kremer (SysAdm), Dept. of Computer Science, Utrecht University Padualaan 14, P.O. Box 80.089, 3508 TB Utrecht, The Netherlands Telephone: +31-30-534104 | UUCP: ...!uunet!mcsun!hp4nl!ruuinf!edwin Telefax : +31-30-513791 | Email: edwin@cs.ruu.nl [131.211.80.5]