Text   |  XML   |  ReML   |   Visible Warnings:

File System Race Condition  at mailbox-list-fs.c:357

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

fs_list_rename_mailbox

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib-storage/list/mailbox-list-fs.c)expand/collapse
Show more  
 302  static int fs_list_rename_mailbox(struct mailbox_list *list,
 303                                    const char *oldname, const char *newname)
 304  {
 305          const char *oldpath, *newpath, *p, *origin;
 306          struct stat st;
 307          mode_t mode;
 308          gid_t gid;
 309   
 310          oldpath = mailbox_list_get_path(list, oldname,
 311                                          MAILBOX_LIST_PATH_TYPE_DIR);
 312          newpath = mailbox_list_get_path(list, newname,
 313[+]                                         MAILBOX_LIST_PATH_TYPE_DIR);
 314   
 315          /* create the hierarchy */
 316          p = strrchr(newpath, '/');
 317          if (p != NULL) {
 318                  mailbox_list_get_dir_permissions(list, NULL, &mode,
 319                                                   &gid, &origin);
 320                  p = t_strdup_until(newpath, p);
 321                  if (mkdir_parents_chgrp(p, mode, gid, origin) < 0 &&
 322                      errno != EEXIST) {
 323                          if (mailbox_list_set_error_from_errno(list))
 324                                  return -1;
 325   
 326                          mailbox_list_set_critical(list,
 327                                  "mkdir_parents(%s) failed: %m", p);
 328                          return -1;
 329                  }
 330          }
 331   
 332          /* first check that the destination mailbox doesn't exist.
 333             this is racy, but we need to be atomic and there's hardly any
 334             possibility that someone actually tries to rename two mailboxes
 335             to same new one */
 336          if (lstat(newpath, &st) == 0) {
 337                  mailbox_list_set_error(list, MAIL_ERROR_EXISTS,
 338                                         "Target mailbox already exists");
 339                  return -1;
 340          } else if (errno == ENOTDIR) {
 341                  mailbox_list_set_error(list, MAIL_ERROR_NOTPOSSIBLE,
 342                          "Target mailbox doesn't allow inferior mailboxes");
 343                  return -1;
 344          } else if (errno != ENOENT && errno != EACCES) {
 345                  mailbox_list_set_critical(list, "lstat(%s) failed: %m",
 346                                            newpath);
 347                  return -1;
 348          }
 349   
 350          if (list->v.rename_mailbox_pre != NULL) {
 351                  if (list->v.rename_mailbox_pre(list, oldname, newname) < 0)
 352                          return -1;
 353          }
 354   
 355          /* NOTE: renaming INBOX works just fine with us, it's simply recreated
 356             the next time it's needed. */
 357          if (rename(oldpath, newpath) < 0) {
Show more  




Change Warning 7280.24987 : File System Race Condition

Priority:
State:
Finding:
Owner:
Note: