25 year old bug fixed in BSD Unices
Here’s a remarkable report on a bug that has been living in BSD for over 25 years. At one time, BSD-hero, Kirk McKusick implemented the dir* library in BSD to prevent applications from having to implement the directory oriented functions themselves. Afterwards he changed 22 programs that were using direct directory handling to using the operating system functions. The bug could prolong itself for 25 years because it manifests itself in a particular (rare) case:
This code will not work as expected when seeking to the second entry of a block where the first has been deleted: seekdir() calls readdir() which happily skips the first entry (it has inode set to zero), and advance to the second entry. When the user now calls readdir() to read the directory entry to which he just seekdir()ed, he does not get the second entry but the third.
Even OSX has the same problem since it has BSD under the hood. The good news is that BSD now even got better and a small consolation for all coders out there: even Kirk McKusick slips one in every now and then. Happy coding.