Text   |  XML   |  ReML   |   Visible Warnings:

File System Race Condition  at unlink-directory.c:106

No properties have been set. | edit properties
Jump to warning location ↓ warning details...
Show Events | Options

unlink_directory_r

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib/unlink-directory.c)expand/collapse
Show more  
 44  static int unlink_directory_r(const char *dir)
 45  {
 46          DIR *dirp;
 47          struct dirent *d;
 48          struct stat st;
 49          int dir_fd, old_errno;
 50   
 51  #ifdef O_NOFOLLOW 
 52          dir_fd = open(dir, O_RDONLY | O_NOFOLLOW);
 53          if (dir_fd == -1)
 54                  return -1;
 55  #else
 56          struct stat st2;
 57   
 58          if (lstat(dir, &st) < 0)
 59                  return -1;
 60   
 61          if (!S_ISDIR(st.st_mode)) {
 62                  errno = ENOTDIR;
 63                  return -1;
 64          }
 65   
 66          dir_fd = open(dir, O_RDONLY);
 67          if (dir_fd == -1)
 68                  return -1;
 69   
 70          if (fstat(dir_fd, &st2) < 0) {
 71                  close_keep_errno(dir_fd);
 72                  return -1;
 73          }
 74   
 75          if (st.st_ino != st2.st_ino ||
 76              !CMP_DEV_T(st.st_dev, st2.st_dev)) {
 77                  /* directory was just replaced with something else. */
 78                  (void)close(dir_fd);
 79                  errno = ENOTDIR;
 80                  return -1;
 81          }
 82  #endif
 83          if (fchdir(dir_fd) < 0) {
 84                  close_keep_errno(dir_fd);
 85                  return -1;
 86          }
 87   
 88          dirp = opendir(".");
 89          if (dirp == NULL) {
 90                  close_keep_errno(dir_fd);
 91                  return -1;
 92          }
 93   
 94          errno = 0;
 95          while ((d = readdir(dirp)) != NULL) {
 96                  if (d->d_name[0] == '.' &&
 97                      (d->d_name[1] == '\0' ||
 98                       (d->d_name[1] == '.' && d->d_name[2] == '\0'))) {
 99                          /* skip . and .. */
 100                          continue;
 101                  }
 102   
 103                  if (unlink(d->d_name) < 0 && errno != ENOENT) {
 104                          old_errno = errno;
 105   
 106                          if (lstat(d->d_name, &st) < 0) {
 107                                  if (errno != ENOENT)
 108                                          break;
 109                                  errno = 0;
 110                          } else if (S_ISDIR(st.st_mode)) {
 111                                  if (unlink_directory_r(d->d_name) < 0) {
 112                                          if (errno != ENOENT)
 113                                                  break;
 114                                          errno = 0;
 115                                  }
 116                                  if (fchdir(dir_fd) < 0)
 117                                          break;
 118   
 119                                  if (rmdir(d->d_name) < 0) {
 120                                          if (errno != ENOENT)
 121                                                  break;
 122                                          errno = 0;
Show more  




Change Warning 7137.24549 : File System Race Condition

Priority:
State:
Finding:
Owner:
Note: