Text   |  XML   |  ReML   |   Visible Warnings:

Null Test After Dereference  at mail-transaction-log-view.c:187

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

mail_transaction_log_view_set

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib-index/mail-transaction-log-view.c)expand/collapse
Show more  
 96  int mail_transaction_log_view_set(struct mail_transaction_log_view *view,
 97                                    uint32_t min_file_seq, uoff_t min_file_offset,
 98                                    uint32_t max_file_seq, uoff_t max_file_offset,
 99                                    bool *reset_r)
 100  {
 101          struct mail_transaction_log_file *file, *const *files;
 102          uoff_t start_offset, end_offset;
 103          unsigned int i;
 104          uint32_t seq;
 105          int ret;
 106   
 107          i_assert(view->log != NULL);
 108          i_assert(min_file_seq <= max_file_seq);
 109   
 110          *reset_r = FALSE;
 111   
 112          if (view->log == NULL) {
 113                  /* transaction log is closed already. this log view shouldn't
 114                     be used anymore. */
 115                  return -1;
 116          }
 117   
 118          if (min_file_seq == 0) {
 119                  /* index file doesn't exist yet. this transaction log should
 120                     start from the beginning */
 121                  if (view->log->files->hdr.prev_file_seq != 0) {
 122                          /* but it doesn't */
 123                          return 0;
 124                  }
 125   
 126                  min_file_seq = view->log->files->hdr.file_seq;
 127                  min_file_offset = 0;
 128   
 129                  if (max_file_seq == 0) {
 130                          max_file_seq = min_file_seq;
 131                          max_file_offset = min_file_offset;
 132                  }
 133          }  
 134   
 135          if (min_file_seq == view->log->files->hdr.prev_file_seq &&
 136              min_file_offset == view->log->files->hdr.prev_file_offset) {
 137                  /* we can skip this */
 138                  min_file_seq = view->log->files->hdr.file_seq;
 139                  min_file_offset = 0;
 140   
 141                  if (min_file_seq > max_file_seq) {
 142                          /* empty view */
 143                          max_file_seq = min_file_seq;
 144                          max_file_offset = min_file_offset;
 145                  }
 146          }
 147   
 148          if (min_file_seq == max_file_seq && min_file_offset > max_file_offset) {
 149                  /* log file offset is probably corrupted in the index file. */
 150                  mail_transaction_log_view_set_corrupted(view,
 151                          "file_seq=%u, min_file_offset (%"PRIuUOFF_T
 152                          ") > max_file_offset (%"PRIuUOFF_T")",
 153                          min_file_seq, min_file_offset, max_file_offset);
 154                  return -1;
 155          }
 156   
 157          if (min_file_offset > 0 &&
 158              min_file_offset < view->log->files->hdr.hdr_size) {
 159                  /* log file offset is probably corrupted in the index file. */
 160                  mail_transaction_log_view_set_corrupted(view,
 161                          "file_seq=%u, min_file_offset (%"PRIuUOFF_T
 162                          ") < hdr_size (%u)",
 163                          min_file_seq, min_file_offset,
 164                          view->log->files->hdr.hdr_size);
 165                  return -1;
 166          }
 167   
 168          view->tail = view->head = file = NULL;
 169          for (seq = min_file_seq; seq <= max_file_seq; seq++) {
 170                  if (file == NULL || file->hdr.file_seq != seq) {
 171                          /* see if we could find the missing file. if we know 
 172                             the max. file sequence, make sure NFS attribute
 173                             cache gets flushed if necessary. */
 174                          bool nfs_flush = max_file_seq != (uint32_t)-1;
 175   
 176                          ret = mail_transaction_log_find_file(view->log, seq,
 177                                                               nfs_flush, &file);
 178                          if (ret <= 0) {
 179                                  if (ret < 0)
 180                                          return -1;
 181   
 182                                  /* not found / corrupted */
 183                                  file = NULL;
 184                          }
 185                  }
 186   
 187                  if (file == NULL || file->hdr.file_seq != seq) {
 188                          if (file == NULL && max_file_seq == (uint32_t)-1 &&
 189                              view->head == view->log->head) {
 190                                  /* we just wanted to sync everything */
 191                                  i_assert(max_file_offset == (uoff_t)-1);
 192                                  max_file_seq = seq-1;
 193                                  break;
 194                          }
 195                          /* if any of the found files reset the index,
 196                             ignore any missing files up to it */
 197                          file = view->tail != NULL ? view->tail :
 198                                  view->log->files;
 199                          for (;; file = file->next) {
 200                                  if (file == NULL ||
 201                                      file->hdr.file_seq > max_file_seq) {
 202                                          /* missing files in the middle */
 203                                          return 0;
 204                                  }
 205   
 206                                  if (file->hdr.file_seq >= seq &&
 207                                      file->hdr.prev_file_seq == 0) {
 208                                          /* we can ignore the missing file */
 209                                          break;
 210                                  }
 211                          }
 212                          seq = file->hdr.file_seq;
 213                          view->tail = NULL;
 214                  }  
 215   
 216                  if (view->tail == NULL)
 217                          view->tail = file;
 218                  view->head = file;
 219                  file = file->next;
 220          }
 221   
 222          if (min_file_offset == 0) {
 223                  /* beginning of the file */
 224                  min_file_offset = view->tail->hdr.hdr_size;
 225                  if (min_file_offset > max_file_offset &&
 226                      min_file_seq == max_file_seq) {
 227                          /* we don't actually want to show anything */
 228                          max_file_offset = min_file_offset;
 229                  }
 230          }
 231          i_assert(min_file_offset >= view->tail->hdr.hdr_size);
 232   
 233          /* we have all of them. update refcounts. */
 234          mail_transaction_log_view_unref_all(view);
 235   
 236          /* Reference all used files. */
 237          for (file = view->tail;; file = file->next) {
 238                  array_append(&view->file_refs, &file, 1);
 239                  file->refcount++;
 240   
 241                  if (file == view->head)
 242                          break;
 243          }
 244   
 245          view->cur = view->tail;
 246          view->cur_offset = view->cur->hdr.file_seq == min_file_seq ?
 247                  min_file_offset : view->cur->hdr.hdr_size;
 248   
 249          /* Map the files only after we've found them all. Otherwise if we map
 250             one file and then another file just happens to get rotated, we could
 251             include both files in the view but skip the last transactions from 
 252             the first file.
 253   
 254             We're mapping the files in reverse order so that _log_file_map()
 255             can verify that prev_file_offset matches how far it actually managed 
 256             to sync the file. */
 257          files = array_idx(&view->file_refs, 0);
 258          for (i = array_count(&view->file_refs); i > 0; i--) {
 259                  file = files[i-1];
 260                  start_offset = file->hdr.file_seq == min_file_seq ?
 261                          min_file_offset : file->hdr.hdr_size;
 262                  end_offset = file->hdr.file_seq == max_file_seq ?
 263                          max_file_offset : (uoff_t)-1;
 264                  ret = mail_transaction_log_file_map(file, start_offset,
 265                                                      end_offset);
 266                  if (ret <= 0)
 267                          return ret;
 268   
 269                  if (file->hdr.prev_file_seq == 0) {
 270                          /* this file resets the index.
 271                             don't bother reading the others. */
 272                          if (view->cur != file ||
 273                              view->cur_offset == file->hdr.hdr_size) {
 274                                  view->cur = file;
 275                                  view->cur_offset = file->hdr.hdr_size;
 276                                  *reset_r = TRUE;
 277                                  break;
 278                          }
 279                          i_assert(i == 1);
 280                  }
 281          }
 282   
 283          i_assert(max_file_seq == (uint32_t)-1 ||
 284                   max_file_seq == view->head->hdr.file_seq);
 285          i_assert(max_file_offset == (uoff_t)-1 ||
 286                   max_file_offset <= view->head->sync_offset);
 287          i_assert(min_file_seq != max_file_seq ||
 288                   max_file_seq != view->head->hdr.file_seq ||
 289                   max_file_offset != (uoff_t)-1 ||
 290                   min_file_offset <= view->head->sync_offset);
 291   
 292          view->prev_file_seq = view->cur->hdr.file_seq;
 293          view->prev_file_offset = view->cur_offset;
 294   
 295          view->min_file_seq = min_file_seq;
 296          view->min_file_offset = min_file_offset;
 297          view->max_file_seq = max_file_seq;
 298          view->max_file_offset = I_MIN(max_file_offset, view->head->sync_offset);
 299          view->broken = FALSE;
 300   
 301          if (mail_transaction_log_file_get_highest_modseq_at(view->cur,
 302                                  view->cur_offset, &view->prev_modseq) < 0)
 303                  return -1;
 304   
 305          i_assert(view->cur_offset <= view->cur->sync_offset);
 306          return 1;
 307  }
Show more  




Change Warning 12153.25709 : Null Test After Dereference

Priority:
State:
Finding:
Owner:
Note: