dtree.c (BUG found, diff enclosed)

Steve Tell sgt at alice.UucP
Wed Apr 30 15:50:55 AEST 1986


I just downloaded and compiled the source to the dtree
directory tree program posted recently.
The version posted chokes on files (not necessarily directories)
whose name has a length of 14 characters.  What happens is
that in the directory entry for such a file,
there is no room for the null padding that usually
precedes the inode-number for the next entry to pad out
the name to the required size.
The result is that the offending file comes up "<file> can't stat"
and then you get a whole slew of strange names that can't be stat'ed,
most containing binary stuff that messes up your terminal.

Here's the fix, direct from diff -c:

*** dtree.c	Wed Apr 30 01:37:00 1986  <-------------OLD FILE
--- ../dtree/dtree.c	Wed Apr 30 01:34:27 1986  <-NEW FILE
***************
*** 406,411
  		    || (Point && dp->d_name[0] == '.'))
  				continue;
  
  		sprintf(sub, "%s", dp->d_name);
  #ifdef LINK
  		if (lstat (sub,&Lstat) == FAIL) {

--- 406,415 -----
  		    || (Point && dp->d_name[0] == '.'))
  				continue;
  
+ #ifndef NEWDIR						/***  Here's the fix ***/
+ 		strncpy(sub, dp->d_name, 14);
+ 		sub[14] = 0;
+ #else
  		sprintf(sub, "%s", dp->d_name);
  #endif	NEWDIR
  #ifdef LINK
***************
*** 407,412
  				continue;
  
  		sprintf(sub, "%s", dp->d_name);
  #ifdef LINK
  		if (lstat (sub,&Lstat) == FAIL) {
  			fprintf(stderr, "%s:lstat can't find\n", sub);

--- 411,417 -----
  		sub[14] = 0;
  #else
  		sprintf(sub, "%s", dp->d_name);
+ #endif	NEWDIR
  #ifdef LINK
  		if (lstat (sub,&Lstat) == FAIL) {
  			fprintf(stderr, "%s:lstat can't find\n", sub);
-----
Note that this only makes a difference on pre-BSD-4.1c file systems.

Steve Tell, AT&T Bell Labs, Murray Hill, NJ



More information about the Comp.sources.unix mailing list