Text   |  XML   |  ReML   |   Visible Warnings:

Null Pointer Dereference  at maildir-sync-index.c:567

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

maildir_sync_index

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib-storage/index/maildir/maildir-sync-index.c)expand/collapse
Show more  
 372  int maildir_sync_index(struct maildir_index_sync_context *ctx,
 373                         bool partial)
 374  {
 375          struct maildir_mailbox *mbox = ctx->mbox;
 376          struct mail_index_view *view = ctx->view;
 377          struct mail_index_view *view2;
 378          struct maildir_uidlist_iter_ctx *iter;
 379          struct mail_index_transaction *trans = ctx->trans;
 380          const struct mail_index_header *hdr;
 381          struct mail_index_header empty_hdr;
 382          const struct mail_index_record *rec;
 383          uint32_t seq, seq2, uid, prev_uid;
 384          enum maildir_uidlist_rec_flag uflags;
 385          const char *filename;
 386          uint32_t uid_validity, next_uid, hdr_next_uid, first_recent_uid;
 387          uint32_t first_uid;
 388          unsigned int changes = 0;
 389          int ret = 0;
 390          time_t time_before_sync;
 391          struct stat st;
 392          bool expunged, full_rescan = FALSE;
 393   
 394          i_assert(!mbox->syncing_commit);
 395   
 396          first_uid = 1;
 397          hdr = mail_index_get_header(view);
 398          uid_validity = maildir_uidlist_get_uid_validity(mbox->uidlist);
 399          if (uid_validity != hdr->uid_validity &&
 400              uid_validity != 0 && hdr->uid_validity != 0) {
 401                  /* uidvalidity changed and index isn't being synced for the
 402                     first time, reset the index so we can add all messages as
 403                     new */
 404                  i_warning("Maildir %s: UIDVALIDITY changed (%u -> %u)",
 405                            mbox->path, hdr->uid_validity, uid_validity);
 406                  mail_index_reset(trans);
 407                  index_mailbox_reset_uidvalidity(&mbox->ibox);
 408                  maildir_uidlist_set_next_uid(mbox->uidlist, 1, TRUE);
 409   
 410                  first_uid = hdr->messages_count + 1;
 411                  memset(&empty_hdr, 0, sizeof(empty_hdr));
 412                  empty_hdr.next_uid = 1;
 413                  hdr = &empty_hdr;
 414          }
 415          hdr_next_uid = hdr->next_uid;
 416   
 417          time_before_sync = time(NULL);
 418          mbox->syncing_commit = TRUE;
 419          seq = prev_uid = 0; first_recent_uid = I_MAX(hdr->first_recent_uid, 1);
 420          t_array_init(&ctx->keywords, MAILDIR_MAX_KEYWORDS);
 421          t_array_init(&ctx->idx_keywords, MAILDIR_MAX_KEYWORDS);
 422          iter = maildir_uidlist_iter_init(mbox->uidlist);
 423[+]         while (maildir_uidlist_iter_next(iter, &uid, &uflags, &filename)) {
 424                  maildir_filename_get_flags(ctx->keywords_sync_ctx, filename,
 425                                             &ctx->flags, &ctx->keywords);
 426   
 427                  i_assert(uid > prev_uid);
 428                  prev_uid = uid;
 429   
 430                  /* the private flags are kept only in indexes. don't use them
 431                     at all even for newly seen mails */
 432                  ctx->flags &= ~mbox->ibox.box.private_flags_mask;
 433   
 434          again:
 435                  ctx->seq = ++seq;
 436                  ctx->uid = uid;
 437   
 438                  if (seq > hdr->messages_count) {
 439                          if (uid < hdr_next_uid) {
 440                                  if (maildir_handle_uid_insertion(ctx, uflags,
 441                                                                   filename,
 442                                                                   uid) < 0)
 443                                          ret = -1;
 444                                  seq--;
 445                                  continue;
 446                          }
 447   
 448                          /* Trust uidlist recent flags only for newly added
 449                             messages. When saving/copying messages with flags 
 450                             they're stored to cur/ and uidlist treats them
 451                             as non-recent. */
 452                          if ((uflags & MAILDIR_UIDLIST_REC_FLAG_RECENT) == 0) {
 453                                  if (uid >= first_recent_uid)
 454                                          first_recent_uid = uid + 1;
 455                          }
 456   
 457                          hdr_next_uid = uid + 1;
 458                          mail_index_append(trans, uid, &seq);
 459                          mail_index_update_flags(trans, seq, MODIFY_REPLACE,
 460                                                  ctx->flags);
 461                          if (array_count(&ctx->keywords) > 0) {
 462                                  struct mail_keywords *kw;
 463   
 464                                  kw = mail_index_keywords_create_from_indexes(
 465                                          mbox->ibox.index, &ctx->keywords);
 466                                  mail_index_update_keywords(trans, seq,
 467                                                             MODIFY_REPLACE, kw);
 468                                  mail_index_keywords_free(&kw);
 469                          }
 470                          continue;
 471                  }
 472   
 473                  rec = mail_index_lookup(view, seq);
 474                  if (uid > rec->uid) {
 475                          /* expunged */
 476                          mail_index_expunge(trans, seq);
 477                          goto again;
 478                  }
 479   
 480                  if (uid < rec->uid) {
 481                          if (maildir_handle_uid_insertion(ctx, uflags,
 482                                                           filename, uid) < 0)
 483                                  ret = -1;
 484                          seq--;
 485                          continue;
 486                  }
 487   
 488                  index_sync_changes_read(ctx->sync_changes, rec->uid, &expunged);
 489                  if (expunged) {
 490                          if (maildir_file_do(mbox, ctx->uid,
 491                                              maildir_expunge, ctx) >= 0) {
 492                                  /* successful expunge */
 493                                  mail_index_expunge(trans, seq);
 494                          }
 495                          if ((++changes % MAILDIR_SLOW_MOVE_COUNT) == 0)
 496                                  maildir_sync_notify(ctx->maildir_sync_ctx);
 497                          continue;
 498                  }
 499   
 500                  /* the private flags are stored only in indexes, keep them */
 501                  ctx->flags |= rec->flags & mbox->ibox.box.private_flags_mask;
 502   
 503                  if (index_sync_changes_have(ctx->sync_changes)) {
 504                          /* apply flag changes to maildir */
 505                          if (maildir_file_do(mbox, ctx->uid,
 506                                              maildir_sync_flags, ctx) < 0)
 507                                  ctx->flags |= MAIL_INDEX_MAIL_FLAG_DIRTY;
 508                          if ((++changes % MAILDIR_SLOW_MOVE_COUNT) == 0)
 509                                  maildir_sync_notify(ctx->maildir_sync_ctx);
 510                  }
 511   
 512                  if ((uflags & MAILDIR_UIDLIST_REC_FLAG_NONSYNCED) != 0) {
 513                          /* partial syncing */
 514                          if ((uflags & MAILDIR_UIDLIST_REC_FLAG_NEW_DIR) != 0) {
 515                                  /* we last saw this mail in new/, but it's
 516                                     not there anymore. possibly expunged,
 517                                     make sure. */
 518                                  full_rescan = TRUE;
 519                          }
 520                          continue;
 521                  }
 522   
 523                  if ((rec->flags & MAIL_INDEX_MAIL_FLAG_DIRTY) != 0) {
 524                          /* we haven't been able to update maildir with this 
 525                             record's flag changes. don't sync them. */
 526                          continue;
 527                  }
 528   
 529                  if (ctx->flags != (rec->flags & MAIL_FLAGS_NONRECENT)) {
 530                          mail_index_update_flags(trans, seq, MODIFY_REPLACE,
 531                                                  ctx->flags);
 532                  }
 533   
 534                  maildir_sync_mail_keywords(ctx, seq);
 535          }
 536          maildir_uidlist_iter_deinit(&iter);
 537          mbox->syncing_commit = FALSE;
 538   
 539          if (!partial) {
 540                  /* expunge the rest */
 541                  for (seq++; seq <= hdr->messages_count; seq++)
 542                          mail_index_expunge(trans, seq);
 543          }
 544   
 545          /* add \Recent flags. use updated view so it contains newly 
 546             appended messages. */
 547          view2 = mail_index_transaction_open_updated_view(trans);
 548          if (mail_index_lookup_seq_range(view2, first_recent_uid, (uint32_t)-1,
 549[+]                                         &seq, &seq2) && seq2 >= first_uid) {
 550                  if (seq < first_uid) {
 551                          /* UIDVALIDITY changed, skip over the old messages */
 552                          seq = first_uid;
 553                  }
 554                  index_mailbox_set_recent_seq(&mbox->ibox, view2, seq, seq2);
 555          }
 556          mail_index_view_close(&view2);
 557   
 558          if (ctx->uidlist_sync_ctx != NULL) {
 559                  if (maildir_uidlist_sync_deinit(&ctx->uidlist_sync_ctx,
 560                                                  TRUE) < 0)
 561                          ret = -1;
 562          }
 563   
 564          if (mbox->ibox.box.v.sync_notify != NULL)
 565                  mbox->ibox.box.v.sync_notify(&mbox->ibox.box, 0, 0);
 566   
 567[+]         if (stat(t_strconcat(mbox->path, "/cur", NULL), &st) == 0) {
Show more  




Change Warning 7322.25920 : Null Pointer Dereference

Priority:
State:
Finding:
Owner:
Note: