[7742] in Athena Bugs
/source/athena/athena.etc/track/files.c
daemon@ATHENA.MIT.EDU (Jonathan I. Kamens)
Mon Jul 15 19:09:10 1991
Date: Mon, 15 Jul 91 16:08:44 -0700
From: "Jonathan I. Kamens" <jik@cats.UCSC.EDU>
To: testers@ATHENA.MIT.EDU
The patch below fixes two bugs:
1. The assumption that "." and ".." exist and are the first two
entries in the directory is bogus and dangerous.
2. A missing closedir() was causing a file descriptor leak.
jik
*** 4.5 1991/07/15 22:47:16
--- files.c 1991/07/15 23:08:07
***************
*** 316,332 ****
do_gripe();
return(-1);
}
- readdir( dirp); readdir( dirp); /* skip . & .. */
strcat( name,"/"); /* XXX: don't copy for recursive call */
leaf = name + strlen( name);
for( next = readdir(dirp); next != NULL; next = readdir(dirp)) {
! if(!(strcmp(next->d_name, "")))
! continue;
strcpy( leaf, next->d_name); /* changes name[] */
removeit( name, 0);
}
leaf[-1] = '\0'; /* XXX: see strcat, above */
if ( rmdir( name) == -1) {
sprintf(errmsg, "can't remove directory %s",name);
--- 324,345 ----
do_gripe();
return(-1);
}
strcat( name,"/"); /* XXX: don't copy for recursive call */
leaf = name + strlen( name);
for( next = readdir(dirp); next != NULL; next = readdir(dirp)) {
! if ((! next->d_name[0]) ||
! ((next->d_name[0] == '.') &&
! ((! next->d_name[1]) ||
! ((next->d_name[1] == '.') &&
! (! next->d_name[2])))))
! continue;
strcpy( leaf, next->d_name); /* changes name[] */
removeit( name, 0);
}
leaf[-1] = '\0'; /* XXX: see strcat, above */
+
+ (void) closedir(dirp);
if ( rmdir( name) == -1) {
sprintf(errmsg, "can't remove directory %s",name);