root/lib/cib/fuzzers/cib_file_fuzzer.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. LLVMFuzzerTestOneInput

   1 /*
   2  * Copyright 2024 the Pacemaker project contributors
   3  *
   4  * The version control history for this file may have further details.
   5  *
   6  * This source code is licensed under the GNU Lesser General Public License
   7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
   8  */
   9 
  10 #include <crm_internal.h>
  11 
  12 #include <stdint.h>
  13 #include <stdio.h>
  14 #include <stdlib.h>
  15 
  16 #include <crm/cib.h>
  17 
  18 int
  19 LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
     /* [previous][next][first][last][top][bottom][index][help] */
  20 {
  21     char *filename = NULL;
  22     int fd = 0;
  23     cib_t *cib = NULL;
  24 
  25     // Have at least some data
  26     if (size < 5) {
  27         return -1; // Do not add input to testing corpus
  28     }
  29 
  30     filename = pcmk__assert_alloc(size + 1, sizeof(char));
  31     memcpy(filename, data, size);
  32     filename[size] = '\0';
  33 
  34     cib = cib_file_new(filename);
  35 
  36     cib_delete(cib);
  37     free(filename);
  38     return 0;
  39 }

/* [previous][next][first][last][top][bottom][index][help] */