Text   |  XML   |  ReML   |   Visible Warnings:

Leak  at mail-index-sync-keywords.c:128

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

keywords_header_add

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib-index/mail-index-sync-keywords.c)expand/collapse
Show more  
 113  keywords_header_add(struct mail_index_sync_map_ctx *ctx,
 114                      const char *keyword_name, unsigned int *keyword_idx_r)
 115  {
 116          struct mail_index_map *map;
 117          const struct mail_index_ext *ext = NULL;
 118          struct mail_index_keyword_header *kw_hdr;
 119          struct mail_index_keyword_header_rec kw_rec;
 120          uint32_t ext_map_idx;
 121          buffer_t *buf = NULL;
 122          size_t keyword_len, rec_offset, name_offset, name_offset_root;
 123          unsigned int keywords_count;
 124   
 125          /* if we crash in the middle of writing the header, the 
 126             keywords are more or less corrupted. avoid that by 
 127             making sure the header is updated atomically. */
 128[+]         map = mail_index_sync_get_atomic_map(ctx);
expand/collapse

mail_index_sync_get_atomic_map

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib-index/mail-index-sync-update.c)expand/collapse
Show more  
 91  struct mail_index_map *
 92  mail_index_sync_get_atomic_map(struct mail_index_sync_map_ctx *ctx)
 93  {
 94          mail_index_sync_move_to_private_memory(ctx);
 95          mail_index_record_map_move_to_private(ctx->view->map);
 96[+]         mail_index_modseq_sync_map_replaced(ctx->modseq_ctx);
expand/collapse

mail_index_modseq_sync_map_replaced

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib-index/mail-index-modseq.c)expand/collapse
Show more  
 504  void mail_index_modseq_sync_map_replaced(struct mail_index_modseq_sync *ctx)
 505  {
 506[+]         ctx->mmap = mail_index_map_modseq(ctx->view);
expand/collapse

mail_index_map_modseq

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib-index/mail-index-modseq.c)expand/collapse
Show more  
 129  static struct mail_index_map_modseq *
 130  mail_index_map_modseq(struct mail_index_view *view)
 131  {
 132          struct mail_index_map_modseq *mmap = view->map->rec_map->modseq;
 133          uint32_t ext_map_idx;
 134   
 135          if (mmap != NULL)
 136                  return mmap;
 137   
 138          /* don't start tracking until we've seen modseq extension intro */
 139          if (!mail_index_map_get_ext_idx(view->map, view->index->modseq_ext_id,
 140                                          &ext_map_idx))
 141                  return NULL;
 142   
 143[+]         mmap = i_new(struct mail_index_map_modseq, 1);
expand/collapse

i_malloc

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib/imem.c)expand/collapse
Show more  
 7  void *i_malloc(size_t size)
 8  {
 9      void *rv = malloc(size);
 10      if( !rv )
 11          abort();
 12      return rv;
Show more  
 144          i_array_init(&mmap->,
 145                        +
 146[+]                      array_count(&view->index->keywords));
 147          view->map->rec_map->modseq = mmap;
 148          return mmap;
Show more  
 507  }
Show more  
 97          ctx->view->map->write_atomic = TRUE;
 98          return ctx->view->map;
Show more  
 129   
 130          if (!mail_index_map_lookup_ext(map, MAIL_INDEX_EXT_KEYWORDS,
 131[+]                                        &ext_map_idx))
 132                  ext_map_idx = (uint32_t)-1;
 133          else {
 134                  /* update existing header */
 135                  ext = array_idx(&map->extensions, ext_map_idx);
 136                  buf = keywords_get_header_buf(map, ext, 1, &keywords_count,
 137                                                &rec_offset, &name_offset_root,
 138[+]                                               &name_offset);
 139          }
 140   
 141          if (buf == NULL) {
 142                  /* create new / replace broken header */
 143                  buf = buffer_create_dynamic(pool_datastack_create(), 512);
 144                  kw_hdr = buffer_append_space_unsafe(buf, sizeof(*kw_hdr));
 145                  kw_hdr->keywords_count = 1;
 146   
 147                  keywords_count = kw_hdr->keywords_count;
 148                  rec_offset = buf->used;
 149                  name_offset_root = rec_offset +
 150                          kw_hdr->keywords_count * sizeof(kw_rec);
 151                  name_offset = 0;
 152          }
 153   
 154          /* add the keyword */
 155          memset(&kw_rec, 0, sizeof(kw_rec));
 156          kw_rec.name_offset = name_offset;
 157   
 158          keyword_len = strlen(keyword_name) + 1;
 159          buffer_write(buf, rec_offset, &kw_rec, sizeof(kw_rec));
 160          buffer_write(buf, name_offset_root, keyword_name, keyword_len);
 161   
 162          rec_offset += sizeof(kw_rec);
 163          kw_rec.name_offset += keyword_len;
 164          name_offset_root += keyword_len;
 165   
 166          if ((buf->used % 4) != 0)
 167                  buffer_append_zero(buf, 4 - (buf->used % 4));
 168   
 169          if (ext == NULL || buf->used > ext->hdr_size ||
 170              (uint32_t)ext->record_size * CHAR_BIT < keywords_count) {
 171                  /* if we need to grow the buffer, add some padding */
 172                  buffer_append_zero(buf, 128);
 173                  keywords_ext_register(ctx, ext_map_idx,
 174                                        ext == NULL ? 0 : ext->reset_id,
 175[+]                                       buf->used, keywords_count);
expand/collapse

keywords_ext_register

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib-index/mail-index-sync-keywords.c)expand/collapse
Show more  
 75  static void keywords_ext_register(struct mail_index_sync_map_ctx *ctx,
 76                                    uint32_t ext_map_idx, uint32_t reset_id,
 77                                    uint32_t hdr_size, uint32_t keywords_count)
 78  {
 79          buffer_t *ext_intro_buf;
 80          struct mail_transaction_ext_intro *u;
 81   
 82          i_assert(keywords_count > 0);
 83   
 84          ext_intro_buf =
 85                  buffer_create_static_hard(pool_datastack_create(), sizeof(*u) +
 86                                            sizeof(MAIL_INDEX_EXT_KEYWORDS)-1);
 87   
 88          u = buffer_append_space_unsafe(ext_intro_buf, sizeof(*u));
 89          u->ext_id = ext_map_idx;
 90          u->reset_id = reset_id;
 91          u->hdr_size = hdr_size;
 92          u->record_size = (keywords_count + CHAR_BIT - 1) / CHAR_BIT;
 93          if ((u->record_size % 4) != 0) {
 94                  /* since we aren't properly aligned anyway,
 95                     reserve one extra byte for future */
 96                  u->record_size++;
 97          }
 98          u->record_align = 1;
 99   
 100          if (ext_map_idx == (uint32_t)-1) {
 101                  u->name_size = strlen(MAIL_INDEX_EXT_KEYWORDS);
 102                  buffer_append(ext_intro_buf, MAIL_INDEX_EXT_KEYWORDS,
 103                                u->name_size);
 104          }
 105   
 106          ctx->internal_update = TRUE;
 107[+]         if (mail_index_sync_ext_intro(ctx, u) < 0)
expand/collapse

mail_index_sync_ext_intro

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib-index/mail-index-sync-ext.c)expand/collapse
Show more  
 461  int mail_index_sync_ext_intro(struct mail_index_sync_map_ctx *ctx,
 462                                const struct mail_transaction_ext_intro *u)
 463  {
 464          struct mail_index_map *map = ctx->view->map;
 465          struct mail_index_ext_header ext_hdr;
 466          const struct mail_index_ext *ext;
 467          const char *name, *error;
 468          uint32_t ext_map_idx;
 469          bool no_shrink;
 470   
 471          /* default to ignoring the following extension updates in case this
 472             intro is corrupted */
 473          ctx->cur_ext_map_idx = (uint32_t)-2;
 474          ctx->cur_ext_ignore = TRUE;
 475   
 476          if (u->ext_id != (uint32_t)-1 &&
 477              (!array_is_created(&map->extensions) ||
 478[+]              u->ext_id >= array_count(&map->extensions))) {
 479                  if (!mail_index_sync_ext_unknown_complain(ctx, u->ext_id))
 480                          return -1;
 481                  mail_index_sync_set_corrupted(ctx,
 482                          "Extension introduction for unknown id %u", u->ext_id);
 483                  return -1;
 484          }
 485   
 486          if (u->ext_id == (uint32_t)-1 && u->name_size == 0) {
 487                  mail_index_sync_set_corrupted(ctx,
 488                          "Extension introduction without id or name");
 489                  return -1;
 490          }
 491   
 492          if (u->ext_id != (uint32_t)-1) {
 493                  name = NULL;
 494                  ext_map_idx = u->ext_id;
 495          } else {
 496                  name = t_strndup(u + 1, u->name_size);
 497                  if (!mail_index_map_lookup_ext(map, name, &ext_map_idx))
 498                          ext_map_idx = (uint32_t)-1;
 499          }
 500          ext = ext_map_idx == (uint32_t)-1 ? NULL :
 501                  array_idx(&map->extensions, ext_map_idx);
 502          if (ext != NULL)
 503                  name = ext->name;
 504   
 505          if (!ctx->internal_update &&
 506              strcmp(name, MAIL_INDEX_EXT_KEYWORDS) == 0) {
 507                  /* Keyword extension is handled internally by the keyword
 508                     code. Any attempt to modify them directly could cause
 509                     assert-crashes later, so prevent them immediately. */
 510                  mail_index_sync_set_corrupted(ctx,
 511                          "Extension introduction for keywords");
 512                  return -1;
 513          }
 514   
 515          memset(&ext_hdr, 0, sizeof(ext_hdr));
 516          ext_hdr.name_size = strlen(name);
 517          ext_hdr.reset_id = u->reset_id;
 518          ext_hdr.hdr_size = u->hdr_size;
 519          ext_hdr.record_size = u->record_size;
 520          ext_hdr.record_align = u->record_align;
 521          no_shrink = (u->flags & MAIL_TRANSACTION_EXT_INTRO_FLAG_NO_SHRINK) != 0;
 522   
 523          /* make sure the header looks valid before doing anything with it */
 524          if (mail_index_map_ext_hdr_check(&map->hdr, &ext_hdr,
 525[+]                                          name, &error) < 0) {
 526                  mail_index_sync_set_corrupted(ctx,
 527                          "Broken extension introduction: %s", error);
 528                  return -1;
 529          }
 530   
 531          if (ext_map_idx != (uint32_t)-1) {
 532                  /* exists already */
 533                  if (u->reset_id == ext->reset_id) {
 534                          /* check if we need to resize anything */
 535[+]                         sync_ext_resize(u, ext_map_idx, ctx, no_shrink);
expand/collapse

sync_ext_resize

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib-index/mail-index-sync-ext.c)expand/collapse
Show more  
 262  sync_ext_resize(const struct mail_transaction_ext_intro *u,
 263                  uint32_t ext_map_idx, struct mail_index_sync_map_ctx *ctx,
 264                  bool no_shrink)
 265  {
 266          struct mail_index_map *map = ctx->view->map;
 267          struct mail_index_ext *ext;
 268          struct mail_index_ext_header *ext_hdr;
 269          uint32_t old_size, new_size, old_record_size;
 270          bool modified = FALSE, reorder = FALSE;
 271   
 272          ext = array_idx_modifiable(&map->extensions, ext_map_idx);
 273   
 274          old_size = MAIL_INDEX_HEADER_SIZE_ALIGN(ext->hdr_size);
 275          new_size = MAIL_INDEX_HEADER_SIZE_ALIGN(u->hdr_size);
 276   
 277          if (new_size < old_size) {
 278                  /* header shrank */
 279                  if (no_shrink)
 280                          new_size = old_size;
 281                  else {
 282                          buffer_delete(map->hdr_copy_buf,
 283                                        ext->hdr_offset + new_size,
 284                                        old_size - new_size);
 285                          ext->hdr_size = u->hdr_size;
 286                          modified = TRUE;
 287                  }
 288          } else if (new_size > old_size) {
 289                  /* header grown */
 290                  buffer_insert_zero(map->hdr_copy_buf,
 291                                     ext->hdr_offset + old_size,
 292                                     new_size - old_size);
 293                  ext->hdr_size = u->hdr_size;
 294                  modified = TRUE;
 295          }
 296          map->hdr_base = map->hdr_copy_buf->data;
 297   
 298          if (ext->record_align < u->record_align ||
 299              (ext->record_align > u->record_align && !no_shrink)) {
 300                  ext->record_align = u->record_align;
 301                  modified = TRUE;
 302                  reorder = TRUE;
 303          }
 304   
 305          old_record_size = ext->record_size;
 306          if (ext->record_size < u->record_size ||
 307              (ext->record_size > u->record_size && !no_shrink)) {
 308                  ext->record_size = u->record_size;
 309                  modified = TRUE;
 310                  reorder = TRUE;
 311          }
 312   
 313          if (modified) {
 314                  i_assert((map->hdr_copy_buf->used % sizeof(uint64_t)) == 0);
 315                  map->hdr_base = map->hdr_copy_buf->data;
 316                  map->hdr.header_size = map->hdr_copy_buf->used;
 317                  map->write_base_header = map->write_ext_header = TRUE;
 318   
 319                  ext_hdr = get_ext_header(map, ext);
 320                  ext_hdr->reset_id = ext->reset_id;
 321                  ext_hdr->hdr_size = ext->hdr_size;
 322                  ext_hdr->record_offset = ext->record_offset;
 323                  ext_hdr->record_size = ext->record_size;
 324                  ext_hdr->record_align = ext->record_align;
 325          }
 326   
 327          if (new_size != old_size) {
 328                  /* move all hdr_offset of all extensions after this one */
 329                  unsigned int i, count = array_count(&map->extensions);
 330                  ssize_t diff = (ssize_t)new_size - (ssize_t)old_size;
 331   
 332                  ext = array_idx_modifiable(&map->extensions, 0);
 333                  for (i = ext_map_idx + 1; i < count; i++) {
 334                          ext[i].ext_offset += diff;
 335                          ext[i].hdr_offset += diff;
 336                  }
 337          }
 338   
 339          if (reorder) {
 340[+]                 map = mail_index_sync_get_atomic_map(ctx);
expand/collapse

mail_index_sync_get_atomic_map

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib-index/mail-index-sync-update.c)expand/collapse
Show more  
 91  struct mail_index_map *
 92  mail_index_sync_get_atomic_map(struct mail_index_sync_map_ctx *ctx)
 93  {
 94[+]         mail_index_sync_move_to_private_memory(ctx);
expand/collapse

mail_index_sync_move_to_private_memory

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib-index/mail-index-sync-update.c)expand/collapse
Show more  
 74  mail_index_sync_move_to_private_memory(struct mail_index_sync_map_ctx *ctx)
 75  {
 76          struct mail_index_map *map = ctx->view->map;
 77   
 78          i_assert(MAIL_INDEX_MAP_IS_IN_MEMORY(map) ||
 79                   map->rec_map->lock_id != 0);
 80   
 81          if (map->refcount > 1) {
 82                  map = mail_index_map_clone(map);
 83                  mail_index_sync_replace_map(ctx, map);
 84          }
 85   
 86          if (!MAIL_INDEX_MAP_IS_IN_MEMORY(ctx->view->map))
 87                  mail_index_map_move_to_memory(ctx->view->map);
 88[+]         mail_index_modseq_sync_map_replaced(ctx->modseq_ctx);
expand/collapse

mail_index_modseq_sync_map_replaced

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib-index/mail-index-modseq.c)expand/collapse
Show more  
 504  void mail_index_modseq_sync_map_replaced(struct mail_index_modseq_sync *ctx)
 505  {
 506          ctx->mmap = mail_index_map_modseq(ctx->view);
 507  }
Show more  
Show more  
Show more  
Show more  
Show more  
Show more  
Show more  




Change Warning 11456.25652 : Leak

Priority:
State:
Finding:
Owner:
Note: