Text   |  XML   |  ReML   |   Visible Warnings:

File System Race Condition  at maildir-keywords.c:336

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

maildir_keywords_commit

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib-storage/index/maildir/maildir-keywords.c)expand/collapse
Show more  
 351  static int maildir_keywords_commit(struct maildir_keywords *mk)
 352  {
 353          struct dotlock *dotlock;
 354          const char *lock_path;
 355          mode_t old_mask;
 356          int i, fd;
 357   
 358          mk->synced = FALSE;
 359   
 360          if (!mk->changed || mk->mbox == NULL)
 361                  return 0;
 362   
 363[+]         lock_path = t_strconcat(mk->path, ".lock", NULL);
 364          (void)unlink(lock_path);
 365   
 366          for (i = 0;; i++) {
 367                  /* we could just create the temp file directly, but doing it 
 368                     this ways avoids potential problems with overwriting
 369                     contents in malicious symlinks */
 370                  old_mask = umask(0777 & ~mk->mbox->ibox.box.file_create_mode);
 371                  fd = file_dotlock_open(&mk->dotlock_settings, mk->path,
 372                                         DOTLOCK_CREATE_FLAG_NONBLOCK, &dotlock);
 373                  umask(old_mask);
 374                  if (fd != -1)
 375                          break;
 376   
 377                  if (errno != ENOENT || i == MAILDIR_DELETE_RETRY_COUNT) {
 378                          mail_storage_set_critical(mk->storage,
 379                                  "file_dotlock_open(%s) failed: %m", mk->path);
 380                          return -1;
 381                  }
 382                  /* the control dir doesn't exist. create it unless the whole 
 383                     mailbox was just deleted. */
 384                  if (!maildir_set_deleted(mk->mbox))
 385                          return -1;
 386          }
 387   
 388[+]         if (maildir_keywords_write_fd(mk, lock_path, fd) < 0) {
expand/collapse

maildir_keywords_write_fd

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib-storage/index/maildir/maildir-keywords.c)expand/collapse
Show more  
 285  static int maildir_keywords_write_fd(struct maildir_keywords *mk,
 286                                       const char *path, int fd)
 287  {
 288          struct maildir_mailbox *mbox = mk->mbox;
 289          struct mailbox *box = &mbox->ibox.box;
 290          const char *const *keywords;
 291          unsigned int i, count;
 292          string_t *str;
 293          struct stat st;
 294   
 295          str = t_str_new(256);
 296[+]         keywords = array_get(&mk->list, &count);
 297          for (i = 0; i < count; i++) {
 298                  if (keywords[i] != NULL)
 299                          str_printfa(str, "%u %s\n", i, keywords[i]);
 300          }
 301[+]         if (write_full(fd, str_data(str), str_len(str)) < 0) {
 302                  mail_storage_set_critical(mk->storage,
 303                                            "write_full(%s) failed: %m", path);
 304                  return -1;
 305          }
 306   
 307          if (fstat(fd, &st) < 0) {
 308                  mail_storage_set_critical(mk->storage,
 309                                            "fstat(%s) failed: %m", path);
 310                  return -1;
 311          }
 312   
 313          if (st.st_gid != box->file_create_gid &&
 314              box->file_create_gid != (gid_t)-1) {
 315                  if (fchown(fd, (uid_t)-1, box->file_create_gid) < 0) {
 316                          if (errno == EPERM) {
 317                                  mail_storage_set_critical(mk->storage, "%s",
 318                                          eperm_error_get_chgrp("fchown", path,
 319                                                  box->file_create_gid,
 320                                                  box->file_create_gid_origin));
 321                          } else {
 322                                  mail_storage_set_critical(mk->storage,
 323                                          "fchown(%s) failed: %m", path);
 324                          }
 325                  }
 326          }
 327   
 328          /* mtime must grow every time */
 329          if (st.st_mtime <= mk->synced_mtime) {
 330                  struct utimbuf ut;
 331   
 332                  mk->synced_mtime = ioloop_time <= mk->synced_mtime ?
 333                          mk->synced_mtime + 1 : ioloop_time;
 334                  ut.actime = ioloop_time;
 335                  ut.modtime = mk->synced_mtime;
 336                  if (utime(path, &ut) < 0) {
Show more  
Show more  




Change Warning 7320.25125 : File System Race Condition

Priority:
State:
Finding:
Owner:
Note: