nasty bug in the 4.2 compatibility routines

Steven M. Kramer smk at axiom.UUCP
Fri Feb 17 11:28:04 AEST 1984


The 4.2 compatibility routines opendir(), seekdir(), readdir(), telldir()
have 2 bugs in the package.  This can cause problems in 2.10 and 2.10.1
B news, anyone trying to port the 4.2 uucp to another machine without
long directories, and any other utility which uses them.

One bug is simply that the structure elements are messed up.

The other more serious bug is due to the wrong variable being checked.
The fix is below, but what happened was that I was porting the 4.2
uucp distribution (which is overall very good) to another machine.
A directory would be opened, read a couple of times, then rewinddir was called
and the directory was read again.  You'd expect the same entries to be reread,
but the seek to the beginning did not happen and the next block (there
was none) could be read in, and so readdir returned 0 (EOF).  This
happened inbetween checking to see if work was to be done in a spool
and actually doing it.  I can envision many other comparable quirks
popping up because of this.

	--steve kramer
		(This was a toughy to track down!)


*** readdir.c.orig	Thu Feb 16 20:14:24 1984
--- readdir.c	Thu Feb 16 20:16:18 1984
***************
*** 42,47
  		dirp->dd_loc += sizeof(struct olddirect);
  		if (dp->od_ino == 0)
  			continue;
  		dir.od_ino = dp->d_ino;
  		strncpy(dir.d_name, dp->od_name, ODIRSIZ);
  		dir.d_name[ODIRSIZ] = '\0'; /* insure null termination */

--- 42,57 -----
  		dirp->dd_loc += sizeof(struct olddirect);
  		if (dp->od_ino == 0)
  			continue;
+ #ifdef AXIOM
+ 		/*
+ 		 * Let's get our structure elements straight.
+ 		 * d_ino is the virtual inode number and od_ino is the real
+ 		 * inode number we have (but don't want to see as
+ 		 * such using this library).
+ 		 * Steve Kramer 2/16/84
+ 		 */
+ 		dir.d_ino = dp->od_ino;
+ #else
  		dir.od_ino = dp->d_ino;
  #endif
  		strncpy(dir.d_name, dp->od_name, ODIRSIZ);
***************
*** 43,48
  		if (dp->od_ino == 0)
  			continue;
  		dir.od_ino = dp->d_ino;
  		strncpy(dir.d_name, dp->od_name, ODIRSIZ);
  		dir.d_name[ODIRSIZ] = '\0'; /* insure null termination */
  		dir.d_namlen = strlen(dir.d_name);

--- 53,59 -----
  		dir.d_ino = dp->od_ino;
  #else
  		dir.od_ino = dp->d_ino;
+ #endif
  		strncpy(dir.d_name, dp->od_name, ODIRSIZ);
  		dir.d_name[ODIRSIZ] = '\0'; /* insure null termination */
  		dir.d_namlen = strlen(dir.d_name);
*** seekdir.c.orig	Thu Feb 16 20:16:57 1984
--- seekdir.c	Thu Feb 16 20:19:53 1984
***************
*** 25,30
  		return;
  	base = loc & ~(DIRBLKSIZ - 1);
  	offset = loc & (DIRBLKSIZ - 1);
  	if (dirp->dd_loc != 0 && (curloc & ~(DIRBLKSIZ - 1)) == base) {
  		dirp->dd_loc = offset;
  		return;

--- 25,43 -----
  		return;
  	base = loc & ~(DIRBLKSIZ - 1);
  	offset = loc & (DIRBLKSIZ - 1);
+ #ifdef AXIOM
+ 	/*
+ 	 * What is intended is to avoid a seek if we are seeking to a
+ 	 * location we have already buffered in core.  However, there
+ 	 * is a special case.  If we want to go to the beginning of the
+ 	 * buffer, the readdir() routine will interpret that as the
+ 	 * signal to read in another buffer, which is not intended.
+ 	 * The value we want to check here then, is the offset into the
+ 	 * buffer we will end up in, not where we are now.
+ 	 * Steve Kramer 2/16/84
+ 	 */
+ 	if ((offset != 0) && ((curloc & ~(DIRBLKSIZ - 1)) == base)) {
+ #else
  	if (dirp->dd_loc != 0 && (curloc & ~(DIRBLKSIZ - 1)) == base) {
  #endif
  		dirp->dd_loc = offset;
***************
*** 26,31
  	base = loc & ~(DIRBLKSIZ - 1);
  	offset = loc & (DIRBLKSIZ - 1);
  	if (dirp->dd_loc != 0 && (curloc & ~(DIRBLKSIZ - 1)) == base) {
  		dirp->dd_loc = offset;
  		return;
  	}

--- 39,45 -----
  	if ((offset != 0) && ((curloc & ~(DIRBLKSIZ - 1)) == base)) {
  #else
  	if (dirp->dd_loc != 0 && (curloc & ~(DIRBLKSIZ - 1)) == base) {
+ #endif
  		dirp->dd_loc = offset;
  		return;
  	}
-- 
	--steve kramer
	{allegra,genrad,ihnp4,utzoo,philabs,uw-beaver}!linus!axiom!smk	(UUCP)
	linus!axiom!smk at mitre-bedford					(MIL)



More information about the Net.bugs mailing list