afl-fuzz.c
static void pivot_inputs(void) {
  struct top_mem* top_cur =  cksum_hash_map[4096]->score_queue;
  u32 id = 0;

  ACTF("Creating hard links for all input files...");

  while (top_cur) {
    struct queue_entry* q = top_cur->testcase;
    u8  *nfn, *rsl = strrchr(q->fname, '/');
    u32 orig_id;

    if (!rsl) rsl = q->fname; else rsl++;

    /* If the original file name conforms to the syntax and the recorded
       ID matches the one we'd assign, just use the original file name.
       This is valuable for resuming fuzzing runs. */

#ifndef SIMPLE_FILES
#  define CASE_PREFIX "id:"
#else
#  define CASE_PREFIX "id_"
#endif /* ^!SIMPLE_FILES */

    if (!strncmp(rsl, CASE_PREFIX, 3) &&
        sscanf(rsl + 3, "%06u", &orig_id) == 1 && orig_id == id) {

      u8* src_str;
      u32 src_id;

      resuming_fuzz = 1;
      nfn = alloc_printf("%s/queue/%s", out_dir, rsl);

      /* Since we're at it, let's also try to find parent and figure out the
         appropriate depth for this entry. */

      src_str = strchr(rsl + 3, ':');

      if (src_str && sscanf(src_str + 1, "%06u", &src_id) == 1) {

        struct top_mem* top_s =  cksum_hash_map[4096]->score_queue;
        while (src_id-- && top_s) top_s = top_s->next;
        struct queue_entry* s =cksum_hash_map[4096]->score_queue->testcase;
        if (s) q->depth = s->depth + 1;

        if (max_depth < q->depth) max_depth = q->depth;

      }

    } else {

      /* No dice - invent a new name, capturing the original one as a
         substring. */

#ifndef SIMPLE_FILES

      u8* use_name = strstr(rsl, ",orig:");

      if (use_name) use_name += 6; else use_name = rsl;
      nfn = alloc_printf("%s/queue/id:%06u,orig:%s", out_dir, id, use_name);

#else

      nfn = alloc_printf("%s/queue/id_%06u", out_dir, id);

#endif /* ^!SIMPLE_FILES */

    }

    /* Pivot to the new queue entry. */

    link_or_copy(q->fname, nfn);
    ck_free(q->fname);
    q->fname = nfn;

    /* Make sure that the passed_det value carries over, too. */

    if (q->passed_det) mark_as_det_done(q);

    top_cur = top_cur->next;
    id++;

  }

  if (in_place_resume) nuke_resume_dir();

}
/* Create hard links for input test cases in the output directory, choosing
   good names and pivoting accordingly. */
Create hard links for input test cases in the output directory, choosing
good names and pivoting accordingly.
Create hard links for input test cases in the output directory choosing good names and pivoting accordingly .
static void pivot_inputs(void) {
  struct top_mem* top_cur =  cksum_hash_map[4096]->score_queue;
  u32 id = 0;
  ACTF("Creating hard links for all input files...");
  while (top_cur) {
    struct queue_entry* q = top_cur->testcase;
    u8  *nfn, *rsl = strrchr(q->fname, '/');
    u32 orig_id;
    if (!rsl) rsl = q->fname; else rsl++;
#ifndef SIMPLE_FILES
#  define CASE_PREFIX "id:"
#else
#  define CASE_PREFIX "id_"
#endif 
    if (!strncmp(rsl, CASE_PREFIX, 3) &&
        sscanf(rsl + 3, "%06u", &orig_id) == 1 && orig_id == id) {
      u8* src_str;
      u32 src_id;
      resuming_fuzz = 1;
      nfn = alloc_printf("%s/queue/%s", out_dir, rsl);
      src_str = strchr(rsl + 3, ':');
      if (src_str && sscanf(src_str + 1, "%06u", &src_id) == 1) {
        struct top_mem* top_s =  cksum_hash_map[4096]->score_queue;
        while (src_id-- && top_s) top_s = top_s->next;
        struct queue_entry* s =cksum_hash_map[4096]->score_queue->testcase;
        if (s) q->depth = s->depth + 1;
        if (max_depth < q->depth) max_depth = q->depth;
      }
    } else {
#ifndef SIMPLE_FILES
      u8* use_name = strstr(rsl, ",orig:");
      if (use_name) use_name += 6; else use_name = rsl;
      nfn = alloc_printf("%s/queue/id:%06u,orig:%s", out_dir, id, use_name);
#else
      nfn = alloc_printf("%s/queue/id_%06u", out_dir, id);
#endif 
    }
    link_or_copy(q->fname, nfn);
    ck_free(q->fname);
    q->fname = nfn;
    if (q->passed_det) mark_as_det_done(q);
    top_cur = top_cur->next;
    id++;
  }
  if (in_place_resume) nuke_resume_dir();
}
static void pivot_inputs ( void ) { struct top_mem * top_cur = cksum_hash_map [ 4096 ] -> score_queue ; u32 id = 0 ; ACTF ( " " ) ; while ( top_cur ) { struct queue_entry * q = top_cur -> testcase ; u8 * nfn , * rsl = strrchr ( q -> fname , ' ' ) ; u32 orig_id ; if ( ! rsl ) rsl = q -> fname ; else rsl ++ ; #ifndef SIMPLE_FILES #  define CASE_PREFIX  "id:" #else #  define CASE_PREFIX  "id_" #endif if ( ! strncmp ( rsl , CASE_PREFIX , 3 ) && sscanf ( rsl + 3 , " " , & orig_id ) == 1 && orig_id == id ) { u8 * src_str ; u32 src_id ; resuming_fuzz = 1 ; nfn = alloc_printf ( " " , out_dir , rsl ) ; src_str = strchr ( rsl + 3 , ' ' ) ; if ( src_str && sscanf ( src_str + 1 , " " , & src_id ) == 1 ) { struct top_mem * top_s = cksum_hash_map [ 4096 ] -> score_queue ; while ( src_id -- && top_s ) top_s = top_s -> next ; struct queue_entry * s = cksum_hash_map [ 4096 ] -> score_queue -> testcase ; if ( s ) q -> depth = s -> depth + 1 ; if ( max_depth < q -> depth ) max_depth = q -> depth ; } } else { #ifndef SIMPLE_FILES u8 * use_name = strstr ( rsl , " " ) ; if ( use_name ) use_name += 6 ; else use_name = rsl ; nfn = alloc_printf ( " " , out_dir , id , use_name ) ; #else nfn = alloc_printf ( " " , out_dir , id ) ; #endif } link_or_copy ( q -> fname , nfn ) ; ck_free ( q -> fname ) ; q -> fname = nfn ; if ( q -> passed_det ) mark_as_det_done ( q ) ; top_cur = top_cur -> next ; id ++ ; } if ( in_place_resume ) nuke_resume_dir ( ) ; }
Create hard links for input test cases in the output directory, choosing
good names and pivoting accordingly.
Create hard links for input test cases in the output directory choosing good names and pivoting accordingly .
/* If the original file name conforms to the syntax and the recorded
       ID matches the one we'd assign, just use the original file name.
       This is valuable for resuming fuzzing runs. */ /* ^!SIMPLE_FILES */ /* Since we're at it, let's also try to find parent and figure out the
         appropriate depth for this entry. */ /* No dice - invent a new name, capturing the original one as a
         substring. */ /* ^!SIMPLE_FILES */ /* Pivot to the new queue entry. */ /* Make sure that the passed_det value carries over, too. */