Text   |  XML   |  ReML   |   Visible Warnings:

Null Pointer Dereference  at mailbox-list-index-sync.c:625

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

mailbox_list_index_sync_recreate_dir

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib-index/mailbox-list-index-sync.c)expand/collapse
Show more  
 530  mailbox_list_index_sync_recreate_dir(struct mailbox_list_index_sync_ctx *ctx,
 531                                       struct mailbox_list_sync_dir *sync_dir,
 532                                       uint32_t offset_pos, bool partial)
 533  {
 534          struct mailbox_list_index *index = ctx->index;
 535          const struct mailbox_list_dir_record *dir;
 536          const struct mailbox_list_record *recs;
 537          struct mailbox_list_dir_record *new_dir;
 538          struct mailbox_list_record *new_recs;
 539          struct mailbox_list_sync_record *sync_recs;
 540          unsigned int src, dest, orig, count, nondeleted_count;
 541          unsigned int space_needed, deleted_space;
 542          uint32_t base_offset, name_pos, size;
 543          void *base;
 544   
 545          i_assert((offset_pos % sizeof(uint32_t)) == 0);
 546          i_assert(offset_pos < index->mmap_size);
 547   
 548          /* count how much space we need and how much we wasted for deleted 
 549             records */
 550          nondeleted_count = 0; space_needed = 0;
 551[+]         sync_recs = array_get_modifiable(&sync_dir->records, &count);
 552          for (src = 0; src < count; src++) {
 553                  if (sync_recs[src].seen || partial) {
 554                          nondeleted_count++;
 555                          if (sync_recs[src].created) {
 556                                  /* new record */
 557                                  space_needed += strlen(sync_recs[src].name) + 1;
 558                          }
 559                  }
 560          }
 561   
 562          /* @UNSAFE */
 563          space_needed += sizeof(*dir) + nondeleted_count * sizeof(*new_recs);
 564          if (mailbox_list_index_sync_alloc_space(ctx, space_needed,
 565[+]                                                 &base, &base_offset) < 0)
 566                  return -1;
 567          /* NOTE: any pointers to the index file may have been invalidated
 568             as a result of growing the the memory area */
 569   
 570          if (sync_dir->offset == 0) {
 571                  dir = NULL;
 572                  recs = NULL;
 573                  deleted_space = 0;
 574          } else {
 575                  /* the offset should have been verified already to be valid */
 576                  i_assert(sync_dir->offset == offset_pos);
 577                  i_assert(sync_dir->offset < index->mmap_size);
 578                  dir = CONST_PTR_OFFSET(index->const_mmap_base,
 579                                         sync_dir->offset);
 580                  recs = MAILBOX_LIST_RECORDS(dir);
 581   
 582                  /* approximate deleted_space. some of the mailbox names will be 
 583                     reused, but don't bother calculating them. */
 584                  deleted_space = sizeof(*dir) + dir->dir_size;
 585          }
 586   
 587          new_dir = base;
 588          new_dir->count = nondeleted_count;
 589          new_dir->dir_size = space_needed;
 590   
 591          new_recs = MAILBOX_LIST_RECORDS_MODIFIABLE(new_dir);
 592          name_pos = (const char *)(new_recs + nondeleted_count) -
 593                  (const char *)base;
 594          for (src = dest = 0; src < count;) {
 595                  if (!sync_recs[src].seen && !partial) {
 596                          /* expunge from mail index */
 597                          uint32_t seq;
 598   
 599                          if (mail_index_lookup_seq(ctx->mail_view,
 600                                                    sync_recs[src].uid, &seq))
 601                                  mail_index_expunge(ctx->trans, seq);
 602                          // FIXME: expunge also NONEXISTENT parents
 603   
 604                          /* If we compress the file, the record must be removed 
 605                             from the array. */
 606                          array_delete(&sync_dir->records, src, 1);
 607                          sync_recs = array_get_modifiable(&sync_dir->records,
 608                                                           &count);
 609                          continue;
 610                  }
 611   
 612                  new_recs[dest].name_hash = sync_recs[src].name_hash;
 613                  new_recs[dest].dir_offset =
 614                          mail_index_uint32_to_offset(sync_recs[src].dir_offset);
 615                  if (sync_recs[src].created) {
 616                          /* new record */
 617                          new_recs[dest].uid = sync_recs[src].uid;
 618                          new_recs[dest].name_offset = base_offset + name_pos;
 619                          size = strlen(sync_recs[src].name) + 1;
 620                          memcpy(PTR_OFFSET(base, name_pos), sync_recs[src].name,
 621                                 size);
 622                          name_pos += size;
 623                  } else {
 624                          /* existing record. need to find its name_offset */
 625                          for (orig = 0; orig < dir->count; orig++) {
Show more  




Change Warning 7265.24746 : Null Pointer Dereference

Priority:
State:
Finding:
Owner:
Note: