Text   |  XML   |  ReML   |   Visible Warnings:

File System Race Condition  at dbox-index.c:650

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

dbox_index_recreate

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib-storage/index/dbox/dbox-index.c)expand/collapse
Show more  
 572  static int dbox_index_recreate(struct dbox_index *index, bool locked)
 573  {
 574          struct mail_storage *storage = &index->mbox->storage->storage;
 575          struct dbox_index_record *records;
 576          struct ostream *output;
 577          struct dbox_index_file_header hdr;
 578          string_t *temp_path, *str;
 579          unsigned int i, count;
 580          int fd, ret = 0;
 581   
 582[+]         temp_path = t_str_new(256);
 583          str_append(temp_path, index->path);
 584   
 585[+]         fd = dbox_index_create_fd(index->mbox, temp_path, locked);
 586          if (fd == -1)
 587                  return -1;
 588   
 589          str = t_str_new(256);
 590          output = o_stream_create_fd_file(fd, 0, FALSE);
 591          o_stream_cork(output);
 592   
 593          dbox_index_header_init(index, &hdr);
 594          o_stream_send(output, &hdr, sizeof(hdr));
 595          o_stream_send(output, "\n", 1);
 596   
 597[+]         records = array_get_modifiable(&index->records, &count);
 598          for (i = 0; i < count; ) {
 599                  if (records[i].status == DBOX_INDEX_FILE_STATUS_UNLINKED) {
 600                          array_delete(&index->records, i, 1);
 601                          records = array_get_modifiable(&index->records, &count);
 602                  } else {
 603                          records[i].file_offset = output->offset;
 604                          str_truncate(str, 0);
 605                          dbox_index_append_record(&records[i], str);
 606                          o_stream_send(output, str_data(str), str_len(str));
 607                          i++;
 608                  }
 609          }
 610   
 611[+]         if (o_stream_flush(output) < 0) {
 612                  mail_storage_set_critical(storage,
 613                          "write(%s) failed: %m", str_c(temp_path));
 614                  ret = -1;
 615          }
 616   
 617          o_stream_destroy(&output);
 618          if (ret == 0 && index->mbox->ibox.fsync_disable) {
 619                  if (fdatasync(fd) < 0) {
 620                          mail_storage_set_critical(storage,
 621                                  "fdatasync(%s) failed: %m", str_c(temp_path));
 622                          ret = -1;
 623                  }
 624          }
 625          if (close(fd) < 0) {
 626                  mail_storage_set_critical(storage,
 627                          "close(%s) failed: %m", str_c(temp_path));
 628                  ret = -1;
 629          }
 630          if (ret == 0) {
 631                  if (locked) {
 632                          if (rename(str_c(temp_path), index->path) < 0) {
 633                                  mail_storage_set_critical(storage,
 634                                          "rename(%s, %s) failed: %m",
 635                                          str_c(temp_path), index->path);
 636                                  ret = -1;
 637                          }
 638                  } else {
 639[+]                         if (nfs_safe_link(str_c(temp_path), index->path,
 640[+]                                           TRUE) < 0 &&
 641                              errno != EEXIST) {
 642                                  mail_storage_set_critical(storage,
 643                                          "link(%s, %s) failed: %m",
 644                                          str_c(temp_path), index->path);
 645                                  ret = -1;
 646                          }
 647                  }
 648          }
 649          if (ret < 0 || !locked) {
 650[+]                 if (unlink(str_c(temp_path)) < 0)
Show more  




Change Warning 7445.24997 : File System Race Condition

Priority:
State:
Finding:
Owner:
Note: