Text   |  XML   |  ReML   |   Visible Warnings:

Redundant Condition  at mail-transaction-log-file.c:411

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

mail_transaction_log_file_read_hdr

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib-index/mail-transaction-log-file.c)expand/collapse
Show more  
 381  mail_transaction_log_file_read_hdr(struct mail_transaction_log_file *file,
 382                                     bool ignore_estale)
 383  {
 384          struct mail_transaction_log_file *f;
 385          int ret;
 386   
 387          i_assert(!MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file));
 388   
 389          if (file->corrupted)
 390                  return 0;
 391   
 392          ret = mail_transaction_log_file_read_header(file);
 393          if (ret < 0) {
 394                  if (errno != ESTALE || !ignore_estale) {
 395                          mail_index_file_set_syscall_error(file->log->index,
 396                                                            file->filepath,
 397                                                            "pread()");
 398                  }
 399                  return -1;
 400          }
 401          if (file->hdr.major_version != MAIL_TRANSACTION_LOG_MAJOR_VERSION) {
 402                  /* incompatible version - fix silently */
 403                  return 0;
 404          }
 405          if (ret < MAIL_TRANSACTION_LOG_HEADER_MIN_SIZE) {
 406                  mail_transaction_log_file_set_corrupted(file,
 407                          "unexpected end of file while reading header");
 408                  return 0;
 409          }
 410   
 411          if (file->hdr.minor_version >= 2 || file->hdr.major_version > 1) {
 412                  /* we have compatibility flags */
 413                  enum mail_index_header_compat_flags compat_flags = 0;
 414   
 415  #ifndef WORDS_BIGENDIAN 
 416                  compat_flags |= MAIL_INDEX_COMPAT_LITTLE_ENDIAN;
 417  #endif
 418                  if (file->hdr.compat_flags != compat_flags) {
 419                          /* architecture change */
 420                          mail_index_set_error(file->log->index,
 421                                               "Rebuilding index file %s: "
 422                                               "CPU architecture changed",
 423                                               file->log->index->filepath);
 424                          return 0;
 425                  }
 426          }
 427          if (file->hdr.hdr_size < MAIL_TRANSACTION_LOG_HEADER_MIN_SIZE) {
 428                  mail_transaction_log_file_set_corrupted(file,
 429                          "Header size too small");
 430                  return 0;
 431          }
 432          if (file->hdr.hdr_size < sizeof(file->hdr)) {
 433                  /* @UNSAFE: smaller than we expected - zero out the fields we 
 434                     shouldn't have filled */
 435                  memset(PTR_OFFSET(&file->hdr, file->hdr.hdr_size), 0,
 436                         sizeof(file->hdr) - file->hdr.hdr_size);
 437          }
 438   
 439          if (file->hdr.indexid == 0) {
 440                  /* corrupted */
 441                  file->corrupted = TRUE;
 442                  mail_index_set_error(file->log->index,
 443                          "Transaction log file %s: marked corrupted",
 444                          file->filepath);
 445                  return 0;
 446          }
 447          if (file->hdr.indexid != file->log->index->indexid) {
 448                  if (file->log->index->indexid != 0 &&
 449                      !file->log->index->initial_create) {
 450                          /* index file was probably just rebuilt and we don't
 451                             know about it yet */
 452                          mail_transaction_log_file_set_corrupted(file,
 453                                  "indexid changed %u -> %u",
 454                                  file->log->index->indexid, file->hdr.indexid);
 455                          return 0;
 456                  }
 457   
 458                  /* creating index file. since transaction log is created 
 459                     first, use the indexid in it to create the main index
 460                     to avoid races. */
 461                  file->log->index->indexid = file->hdr.indexid;
 462          }
 463   
 464          /* make sure we already don't have a file with the same sequence 
 465             opened. it shouldn't happen unless the old log file was 
 466             corrupted. */
 467          for (f = file->log->files; f != NULL; f = f->next) {
 468                  if (f->hdr.file_seq == file->hdr.file_seq) {
 469                          /* mark the old file corrupted. we can't safely remove
 470                             it from the list however, so return failure. */
 471                          mail_transaction_log_file_set_corrupted(f,
 472                                  "duplicate transaction log sequence (%u)",
 473                                  f->hdr.file_seq);
 474                          return 0;
 475                  }
 476          }
 477   
 478          file->sync_highest_modseq = file->hdr.initial_modseq;
 479          return 1;
 480  }
Show more  




Change Warning 7196.24991 : Redundant Condition

Priority:
State:
Finding:
Owner:
Note: