SVR2.2 "ls" bug

Guy Harris guy at sun.uucp
Sat Jul 27 19:44:53 AEST 1985


> When using any of the multi-column modes of "ls" (e.g. -x or -C), the column
> spacing is normally (length of longest filename in listing + 2).  However,
> if any of the filenames being listed are the maximum length for a filename
> (14 chars), the column spacing suddenly becomes 44 chars.

> Probable cause: there are two different constants for maximum widths of
> things, and the programmer used the wrong one someplace.  I don't have
> source to fix it.

Nope.  The problem is that the code in "readdir" that reads directory
entries and computes the maximum length of all the names it's seen doesn't
realize that directory entries are NOT necessarily terminated with a NUL
character.  As such, if the file's name is exactly DIRSIZ characters, the
"strlen" goes past the end and keeps going until (if you're lucky) it
encounters a zero byte.

Note that if S5 as distributed had the directory library, and used it, this
bug would go away by magic; the directory library makes sure the file name
is NUL-terminated.

	Guy Harris



More information about the Net.bugs.usg mailing list