LCOV - code coverage report
Current view: top level - fuzz - fuzz_options.c (source / functions) Coverage Total Hit
Test: Code coverage Lines: 31.6 % 19 6
Test Date: 2025-12-04 16:15:14 Functions: 100.0 % 1 1
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 25.0 % 8 2

             Branch data     Line data    Source code
       1                 :             : /* Copyright (c) 2020, Red Hat, Inc.
       2                 :             :  *
       3                 :             :  * Authors:  Jakub Jelen <jjelen@redhat.com>
       4                 :             :  *
       5                 :             :  * This code is licensed under the GNU LGPL, version 2.1 or later.
       6                 :             :  * See the COPYING file in the top-level directory.
       7                 :             :  */
       8                 :             : 
       9                 :             : #include <stdlib.h>
      10                 :             : #include <string.h>
      11                 :             : #include <libcacard.h>
      12                 :             : 
      13                 :             : #include "fuzzer.h"
      14                 :             : #include "vcard_emul_type.h"
      15                 :             : 
      16                 :             : /* Copied internal structures from vcard_emul_nss.c */
      17                 :             : struct VirtualReaderOptionsStruct {
      18                 :             :     char *name;
      19                 :             :     char *vname;
      20                 :             :     VCardEmulType card_type;
      21                 :             :     char *type_params;
      22                 :             :     char **cert_name;
      23                 :             :     int cert_count;
      24                 :             : };
      25                 :             : 
      26                 :             : struct VCardEmulOptionsStruct {
      27                 :             :     char *nss_db;
      28                 :             :     struct VirtualReaderOptionsStruct *vreader;
      29                 :             :     int vreader_count;
      30                 :             :     VCardEmulType hw_card_type;
      31                 :             :     char *hw_type_params;
      32                 :             :     int use_hw;
      33                 :             : };
      34                 :             : 
      35                 :             : /* We do not want to fuzz inputs longer than 1024 bytes to avoid need for
      36                 :             :  * dynamic reallocation inside of the fuzzer. Anything longer should be
      37                 :             :  * possible to express with shorter strings
      38                 :             :  */
      39                 :             : size_t kMaxInputLength = 1024;
      40                 :             : 
      41                 :           1 : int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
      42                 :             : {
      43                 :             :     int i, j;
      44                 :             :     VCardEmulOptions *options = NULL;
      45                 :             :     struct VCardEmulOptionsStruct *my_options = NULL;
      46                 :             :     char args[1025];
      47                 :             : 
      48         [ -  + ]:           1 :     if (Size > kMaxInputLength) {
      49                 :           0 :         g_debug("Too long input option");
      50                 :           0 :         return 0;
      51                 :             :     }
      52                 :             : 
      53                 :           1 :     memcpy(args, Data, Size);
      54                 :           1 :     args[Size] = '\0';
      55                 :           1 :     options = vcard_emul_options(args);
      56         [ -  + ]:           1 :     if (options == NULL) {
      57                 :             :         /* Invalid input -- the function should have cleaned up for itself */
      58                 :             :         return 0;
      59                 :             :     }
      60                 :             : 
      61                 :             :     /* There is no sensible way to free options if they were valid */
      62                 :             :     my_options = (struct VCardEmulOptionsStruct *)options;
      63         [ #  # ]:           0 :     for (i = 0; i < my_options->vreader_count; i++) {
      64                 :           0 :         g_free(my_options->vreader[i].name);
      65                 :           0 :         g_free(my_options->vreader[i].vname);
      66                 :           0 :         g_free(my_options->vreader[i].type_params);
      67         [ #  # ]:           0 :         for (j = 0; j < my_options->vreader[i].cert_count; j++) {
      68                 :           0 :             g_free(my_options->vreader[i].cert_name[j]);
      69                 :             :         }
      70                 :           0 :         g_free(my_options->vreader[i].cert_name);
      71                 :             :     }
      72                 :           0 :     g_free(my_options->vreader);
      73                 :           0 :     g_free(my_options->hw_type_params);
      74                 :           0 :     g_free(my_options->nss_db);
      75                 :             :     /* The invalid pointers will be overwritten on next call to parse the options */
      76                 :             : 
      77                 :           0 :     return 0;
      78                 :             : }
      79                 :             : 
      80                 :             : /* vim: set ts=4 sw=4 tw=0 noet expandtab: */
        

Generated by: LCOV version 2.0-1