Text   |  XML   |  ReML   |   Visible Warnings:

Ignored Return Value  at maildir-sync.c:288

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

maildir_fix_duplicate

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib-storage/index/maildir/maildir-sync.c)expand/collapse
Show more  
 276  static int maildir_fix_duplicate(struct maildir_sync_context *ctx,
 277                                   const char *dir, const char *fname2)
 278  {
 279          const char *fname1, *path1, *path2;
 280          const char *new_fname, *new_path;
 281          struct stat st1, st2;
 282   
 283          fname1 = maildir_uidlist_sync_get_full_filename(ctx->uidlist_sync_ctx,
 284                                                          fname2);
 285          i_assert(fname1 != NULL);
 286   
 287          path1 = t_strconcat(dir, "/", fname1, NULL);
 288          path2 = t_strconcat(dir, "/", fname2, NULL);
 289   
 290          if (stat(path1, &st1) < 0 || stat(path2, &st2) < 0) {
 291                  /* most likely the files just don't exist anymore.
 292                     don't really care about other errors much. */
 293                  return 0;
 294          }
 295          if (st1.st_ino == st2.st_ino &&
 296              CMP_DEV_T(st1.st_dev, st2.st_dev)) {
 297                  /* Files are the same. this means either a race condition
 298                     between stat() calls, or that the files were link()ed. */
 299                  if (st1.st_nlink > 1 && st2.st_nlink == st1.st_nlink &&
 300                      st1.st_ctime == st2.st_ctime &&
 301                      st1.st_ctime < ioloop_time - DUPE_LINKS_DELETE_SECS) {
 302                          /* The file has hard links and it hasn't had any
 303                             changes (such as renames) for a while, so this
 304                             isn't a race condition.
 305   
 306                             rename()ing one file on top of the other would fix 
 307                             this safely, except POSIX decided that rename()
 308                             doesn't work that way. So we'll have unlink() one 
 309                             and hope that another process didn't just decide to 
 310                             unlink() the other (uidlist lock prevents this from
 311                             happening) */
 312                          if (unlink(path2) == 0)
 313                                  i_warning("Unlinked a duplicate: %s", path2);
 314                          else {
 315                                  mail_storage_set_critical(
 316                                          &ctx->mbox->storage->storage,
 317                                          "unlink(%s) failed: %m", path2);
 318                          }
 319                  }
 320                  return 0;
 321          }
 322   
 323          new_fname = maildir_filename_generate();
 324          new_path = t_strconcat(ctx->mbox->path, "/new/", new_fname, NULL);
 325   
 326          if (rename(path2, new_path) == 0)
 327                  i_warning("Fixed a duplicate: %s -> %s", path2, new_fname);
 328          else if (errno != ENOENT) {
 329                  mail_storage_set_critical(&ctx->mbox->storage->storage,
 330                          "Couldn't fix a duplicate: rename(%s, %s) failed: %m",
 331                          path2, new_path);
 332                  return -1;
 333          }
 334          return 0;
 335  }
Show more  




Change Warning 8183.26094 : Ignored Return Value

Priority:
State:
Finding:
Owner:
Note: