Text   |  XML   |  ReML   |   Visible Warnings:

Null Test After Dereference  at maildir-copy.c:162

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

maildir_copy_hardlink

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib-storage/index/maildir/maildir-copy.c)expand/collapse
Show more  
 129  maildir_copy_hardlink(struct maildir_transaction_context *t, struct mail *mail,
 130                        enum mail_flags flags, struct mail_keywords *keywords,
 131                        struct mail *dest_mail)
 132  {
 133          struct maildir_mailbox *dest_mbox =
 134                  (struct maildir_mailbox *)t->ictx.ibox;
 135          struct maildir_mailbox *src_mbox;
 136          struct hardlink_ctx do_ctx;
 137          const char *path, *filename = NULL;
 138   
 139          i_assert((t->ictx.flags & MAILBOX_TRANSACTION_FLAG_EXTERNAL) != 0);
 140   
 141          if (strcmp(mail->box->storage->name, MAILDIR_STORAGE_NAME) == 0)
 142                  src_mbox = (struct maildir_mailbox *)mail->box;
 143          else if (strcmp(mail->box->storage->name, "raw") == 0) {
 144                  /* deliver uses raw format */
 145                  src_mbox = NULL;
 146          } else {
 147                  /* Can't hard link files from the source storage */
 148                  return 0;
 149          }
 150   
 151          if (t->save_ctx == NULL)
 152                  t->save_ctx = maildir_save_transaction_init(t);
 153   
 154          /* don't allow caller to specify recent flag */
 155          flags &= ~MAIL_RECENT;
 156          if (dest_mbox->ibox.keep_recent)
 157                  flags |= MAIL_RECENT;
 158   
 159          memset(&do_ctx, 0, sizeof(do_ctx));
 160          do_ctx.dest_path = str_new(default_pool, 512);
 161   
 162          if (dest_mbox->storage->copy_preserve_filename && src_mbox != NULL) {
 163                  enum maildir_uidlist_rec_flag src_flags;
 164                  const char *src_fname;
 165   
 166                  /* see if the filename exists in destination maildir's
 167                     uidlist. if it doesn't, we can use it. otherwise generate
 168                     a new filename. FIXME: There's a race condition here if 
 169                     another process is just doing the same copy. */
 170                  if (maildir_uidlist_lookup(src_mbox->uidlist,
 171                                             mail->uid, &src_flags,
 172                                             &src_fname) > 0 &&
 173                      maildir_uidlist_refresh(dest_mbox->uidlist) >= 0 &&
 174                      maildir_uidlist_get_full_filename(dest_mbox->uidlist,
 175                                                        src_fname) == NULL)
 176                          filename = t_strcut(src_fname, ':');
 177          }
 178          if (filename == NULL) {
 179                  /* the generated filename is _always_ unique, so we don't
 180                     bother trying to check if it already exists */
 181                  do_ctx.dest_fname = maildir_filename_generate();
 182          } else {
 183                  do_ctx.dest_fname = filename;
 184                  do_ctx.preserve_filename = TRUE;
 185          }
 186   
 187          /* FIXME: We could hardlink the files directly to destination, but 
 188             that would require checking if someone else had already assigned 
 189             UIDs for them after we have the uidlist locked. Index would also 
 190             need to be properly not-updated somehow.. */
 191  #if 0 
 192          if (keywords == NULL || keywords->count == 0) {
 193                  /* no keywords, hardlink directly to destination */
 194                  if (flags == MAIL_RECENT) {
 195                          str_printfa(do_ctx.dest_path, "%s/new/%s",
 196                                      dest_mbox->path, do_ctx.dest_fname);
 197                          do_ctx.base_end_pos = str_len(do_ctx.dest_path);
 198                  } else {
 199                          str_printfa(do_ctx.dest_path, "%s/cur/",
 200                                      dest_mbox->path);
 201                          do_ctx.base_end_pos = str_len(do_ctx.dest_path) +
 202                                  strlen(do_ctx.dest_fname);
 203                          str_append(do_ctx.dest_path,
 204                                     maildir_filename_set_flags(NULL,
 205                                                                do_ctx.dest_fname,
 206                                                                flags, NULL));
 207                  }
 208          } else 
 209  #endif
 210          {
 211                  /* keywords, hardlink to tmp/ with basename and later when we
 212                     have uidlist locked, move it to new/cur. */
 213                  str_printfa(do_ctx.dest_path, "%s/tmp/%s",
 214                              dest_mbox->path, do_ctx.dest_fname);
 215                  do_ctx.base_end_pos = str_len(do_ctx.dest_path);
 216          }
 217          if (src_mbox != NULL) {
 218                  /* maildir */
 219                  if (maildir_file_do(src_mbox, mail->uid,
 220                                      do_hardlink, &do_ctx) < 0)
 221                          return -1;
 222          } else {
 223                  /* raw / deliver */
 224                  if (mail_get_special(mail, MAIL_FETCH_UIDL_FILE_NAME,
 225                                       &path) < 0 || *path == '\0')
 226                          return 0;
 227                  if (do_hardlink(dest_mbox, path, &do_ctx) < 0)
 228                          return -1;
 229          }
 230   
 231          if (!do_ctx.success) {
 232                  /* couldn't copy with hardlinking, fallback to copying */
 233                  return 0;
 234          }
 235   
 236  #if 0 
 237          if (keywords == NULL || keywords->count == 0) {
 238                  /* hardlinked to destination, set hardlinked-flag */
 239                  maildir_save_add(t, do_ctx.dest_fname,
 240                                   flags | MAILDIR_SAVE_FLAG_HARDLINK, NULL,
 241                                   dest_mail);
 242          } else 
 243  #endif
 244  {
 245                  /* hardlinked to tmp/, treat as normal copied mail */
 246                  maildir_save_add(t, do_ctx.dest_fname, flags, keywords,
 247                                   dest_mail);
 248          }
 249          return 1;
 250  }
Show more  




Change Warning 12171.26022 : Null Test After Dereference

Priority:
State:
Finding:
Owner:
Note: