LLVMFuzzerTestOneInput:
   42|    902|{
   43|    902|    int i, j;
   44|    902|    VCardEmulOptions *options = NULL;
   45|    902|    struct VCardEmulOptionsStruct *my_options = NULL;
   46|    902|    char args[1025];
   47|       |
   48|    902|    if (Size > kMaxInputLength) {
  ------------------
  |  Branch (48:9): [True: 12, False: 890]
  ------------------
   49|     12|        g_debug("Too long input option");
  ------------------
  |  |  344|     12|#define g_debug(...)    g_log (G_LOG_DOMAIN,         \
  |  |  ------------------
  |  |  |  |  296|     12|#define G_LOG_DOMAIN    ((gchar*) 0)
  |  |  ------------------
  |  |  345|     12|                               G_LOG_LEVEL_DEBUG,    \
  |  |  346|     12|                               __VA_ARGS__)
  ------------------
   50|     12|        return 0;
   51|     12|    }
   52|       |
   53|    890|    memcpy(args, Data, Size);
   54|    890|    args[Size] = '\0';
   55|    890|    options = vcard_emul_options(args);
   56|    890|    if (options == NULL) {
  ------------------
  |  Branch (56:9): [True: 588, False: 302]
  ------------------
   57|       |        /* Invalid input -- the function should have cleaned up for itself */
   58|    588|        return 0;
   59|    588|    }
   60|       |
   61|       |    /* There is no sensible way to free options if they were valid */
   62|    302|    my_options = (struct VCardEmulOptionsStruct *)options;
   63|    928|    for (i = 0; i < my_options->vreader_count; i++) {
  ------------------
  |  Branch (63:17): [True: 626, False: 302]
  ------------------
   64|    626|        g_free(my_options->vreader[i].name);
   65|    626|        g_free(my_options->vreader[i].vname);
   66|    626|        g_free(my_options->vreader[i].type_params);
   67|  3.50k|        for (j = 0; j < my_options->vreader[i].cert_count; j++) {
  ------------------
  |  Branch (67:21): [True: 2.87k, False: 626]
  ------------------
   68|  2.87k|            g_free(my_options->vreader[i].cert_name[j]);
   69|  2.87k|        }
   70|    626|        g_free(my_options->vreader[i].cert_name);
   71|    626|    }
   72|    302|    g_free(my_options->vreader);
   73|    302|    g_free(my_options->hw_type_params);
   74|    302|    g_free(my_options->nss_db);
   75|       |    /* The invalid pointers will be overwritten on next call to parse the options */
   76|       |
   77|    302|    return 0;
   78|    890|}

vcard_emul_options:
 1284|    890|{
 1285|    890|    int i, j, reader_count = 0;
 1286|    890|    VCardEmulOptions *opts;
 1287|       |
 1288|       |    /* Allow the future use of allocating the options structure on the fly */
 1289|    890|    memcpy(&options, &default_options, sizeof(options));
 1290|    890|    opts = &options;
 1291|       |
 1292|  2.88k|    do {
 1293|  2.88k|        args = strip(args); /* strip off the leading spaces */
 1294|  2.88k|        if (*args == ',') {
  ------------------
  |  Branch (1294:13): [True: 406, False: 2.48k]
  ------------------
 1295|    406|            args++;
 1296|    406|            continue;
 1297|    406|        }
 1298|       |        /* soft=(slot_name,virt_name,emul_type,emul_flags,cert_1, (no eol)
 1299|       |         *       cert_2,cert_3...) */
 1300|  2.48k|        if (strncmp(args, "soft=", 5) == 0) {
  ------------------
  |  Branch (1300:13): [True: 1.21k, False: 1.26k]
  ------------------
 1301|  1.21k|            const char *name;
 1302|  1.21k|            size_t name_length;
 1303|  1.21k|            const char *vname;
 1304|  1.21k|            size_t vname_length;
 1305|  1.21k|            const char *type_params;
 1306|  1.21k|            size_t type_params_length;
 1307|  1.21k|            char type_str[100];
 1308|  1.21k|            VCardEmulType type;
 1309|  1.21k|            int count;
 1310|  1.21k|            VirtualReaderOptions *vreaderOpt;
 1311|       |
 1312|  1.21k|            args = strip(args + 5);
 1313|  1.21k|            if (*args != '(') {
  ------------------
  |  Branch (1313:17): [True: 24, False: 1.19k]
  ------------------
 1314|     24|                fprintf(stderr, "Error: invalid soft specification.\n");
 1315|     24|                goto fail;
 1316|     24|            }
 1317|  1.19k|            args = strip(args+1);
 1318|       |
 1319|  1.19k|            NEXT_TOKEN(name)
  ------------------
  |  | 1273|  1.19k|            (token) = args; \
  |  | 1274|  1.19k|            args = strpbrk(args, ",)"); \
  |  | 1275|  1.19k|            if (args == NULL || *args == 0 || *args == ')') { \
  |  |  ------------------
  |  |  |  Branch (1275:17): [True: 15, False: 1.17k]
  |  |  |  Branch (1275:33): [True: 0, False: 1.17k]
  |  |  |  Branch (1275:47): [True: 1, False: 1.17k]
  |  |  ------------------
  |  | 1276|     16|                fprintf(stderr, "Error: invalid soft specification.\n"); \
  |  | 1277|     16|                goto fail; \
  |  | 1278|     16|            } \
  |  | 1279|  1.19k|            (token##_length) = args - (token); \
  |  | 1280|  1.17k|            args = strip(args+1);
  ------------------
 1320|  1.17k|            NEXT_TOKEN(vname)
  ------------------
  |  | 1273|  1.17k|            (token) = args; \
  |  | 1274|  1.17k|            args = strpbrk(args, ",)"); \
  |  | 1275|  1.17k|            if (args == NULL || *args == 0 || *args == ')') { \
  |  |  ------------------
  |  |  |  Branch (1275:17): [True: 15, False: 1.16k]
  |  |  |  Branch (1275:33): [True: 0, False: 1.16k]
  |  |  |  Branch (1275:47): [True: 1, False: 1.15k]
  |  |  ------------------
  |  | 1276|     16|                fprintf(stderr, "Error: invalid soft specification.\n"); \
  |  | 1277|     16|                goto fail; \
  |  | 1278|     16|            } \
  |  | 1279|  1.17k|            (token##_length) = args - (token); \
  |  | 1280|  1.15k|            args = strip(args+1);
  ------------------
 1321|  1.15k|            NEXT_TOKEN(type_params)
  ------------------
  |  | 1273|  1.15k|            (token) = args; \
  |  | 1274|  1.15k|            args = strpbrk(args, ",)"); \
  |  | 1275|  1.15k|            if (args == NULL || *args == 0 || *args == ')') { \
  |  |  ------------------
  |  |  |  Branch (1275:17): [True: 15, False: 1.14k]
  |  |  |  Branch (1275:33): [True: 0, False: 1.14k]
  |  |  |  Branch (1275:47): [True: 1, False: 1.14k]
  |  |  ------------------
  |  | 1276|     16|                fprintf(stderr, "Error: invalid soft specification.\n"); \
  |  | 1277|     16|                goto fail; \
  |  | 1278|     16|            } \
  |  | 1279|  1.15k|            (token##_length) = args - (token); \
  |  | 1280|  1.14k|            args = strip(args+1);
  ------------------
 1322|  1.14k|            type_params_length = MIN(type_params_length, sizeof(type_str)-1);
  ------------------
  |  |  805|  1.14k|#define MIN(a, b)  (((a) < (b)) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (805:21): [True: 1.13k, False: 5]
  |  |  ------------------
  ------------------
 1323|  1.14k|            memcpy(type_str, type_params, type_params_length);
 1324|  1.14k|            type_str[type_params_length] = '\0';
 1325|  1.14k|            type = vcard_emul_type_from_string(type_str);
 1326|  1.14k|            if (type == VCARD_EMUL_NONE) {
  ------------------
  |  Branch (1326:17): [True: 39, False: 1.10k]
  ------------------
 1327|     39|                fprintf(stderr, "Error: invalid smartcard type '%s'.\n",
 1328|     39|                        type_str);
 1329|     39|                goto fail;
 1330|     39|            }
 1331|       |
 1332|  2.20k|            NEXT_TOKEN(type_params)
  ------------------
  |  | 1273|  1.10k|            (token) = args; \
  |  | 1274|  1.10k|            args = strpbrk(args, ",)"); \
  |  | 1275|  1.10k|            if (args == NULL || *args == 0 || *args == ')') { \
  |  |  ------------------
  |  |  |  Branch (1275:17): [True: 7, False: 1.09k]
  |  |  |  Branch (1275:33): [True: 0, False: 1.09k]
  |  |  |  Branch (1275:47): [True: 1, False: 1.09k]
  |  |  ------------------
  |  | 1276|      8|                fprintf(stderr, "Error: invalid soft specification.\n"); \
  |  | 1277|      8|                goto fail; \
  |  | 1278|      8|            } \
  |  | 1279|  1.10k|            (token##_length) = args - (token); \
  |  | 1280|  1.09k|            args = strip(args+1);
  ------------------
 1333|       |
 1334|  2.20k|            if (*args == 0) {
  ------------------
  |  Branch (1334:17): [True: 10, False: 1.08k]
  ------------------
 1335|     10|                fprintf(stderr, "Error: missing cert specification.\n");
 1336|     10|                goto fail;
 1337|     10|            }
 1338|       |
 1339|  1.08k|            if (opts->vreader_count >= reader_count) {
  ------------------
  |  Branch (1339:17): [True: 354, False: 732]
  ------------------
 1340|    354|                reader_count += READER_STEP;
  ------------------
  |  | 1264|    354|#define READER_STEP 4
  ------------------
 1341|    354|                opts->vreader = g_renew(VirtualReaderOptions, opts->vreader,
  ------------------
  |  |  313|    354|#define g_renew(struct_type, mem, n_structs)		_G_RENEW (struct_type, mem, n_structs, realloc)
  |  |  ------------------
  |  |  |  |  241|    354|	(struct_type *) (G_GNUC_EXTENSION ({			\
  |  |  |  |  ------------------
  |  |  |  |  |  |   54|    354|#define G_GNUC_EXTENSION __extension__
  |  |  |  |  ------------------
  |  |  |  |  242|    354|	  gsize __n = (gsize) (n_structs);			\
  |  |  |  |  243|    354|	  gsize __s = sizeof (struct_type);			\
  |  |  |  |  244|    354|	  gpointer __p = (gpointer) (mem);			\
  |  |  |  |  245|    354|	  if (__s == 1)						\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (245:8): [True: 0, False: 354]
  |  |  |  |  ------------------
  |  |  |  |  246|    354|	    __p = g_##func (__p, __n);				\
  |  |  |  |  247|    354|	  else if (__builtin_constant_p (__n) &&		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (247:13): [True: 0, False: 354]
  |  |  |  |  ------------------
  |  |  |  |  248|    354|	           (__s == 0 || __n <= G_MAXSIZE / __s))	\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (248:14): [True: 0, False: 0]
  |  |  |  |  |  Branch (248:26): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  249|    354|	    __p = g_##func (__p, __n * __s);			\
  |  |  |  |  250|    354|	  else							\
  |  |  |  |  251|    354|	    __p = g_##func##_n (__p, __n, __s);			\
  |  |  |  |  252|    354|	  __p;							\
  |  |  |  |  253|    354|	}))
  |  |  ------------------
  ------------------
 1342|    354|                                        reader_count);
 1343|    354|            }
 1344|  1.08k|            vreaderOpt = &opts->vreader[opts->vreader_count];
 1345|  1.08k|            vreaderOpt->name = g_strndup(name, name_length);
 1346|  1.08k|            vreaderOpt->vname = g_strndup(vname, vname_length);
 1347|  1.08k|            vreaderOpt->card_type = type;
 1348|  1.08k|            vreaderOpt->type_params =
 1349|  1.08k|                g_strndup(type_params, type_params_length);
 1350|  1.08k|            count = count_tokens(args, ',', ')') + 1;
 1351|  1.08k|            vreaderOpt->cert_count = count;
 1352|  1.08k|            vreaderOpt->cert_name = g_new(char *, count);
  ------------------
  |  |  282|  1.08k|#define g_new(struct_type, n_structs)			_G_NEW (struct_type, n_structs, malloc)
  |  |  ------------------
  |  |  |  |  227|  1.08k|	(struct_type *) (G_GNUC_EXTENSION ({			\
  |  |  |  |  ------------------
  |  |  |  |  |  |   54|  1.08k|#define G_GNUC_EXTENSION __extension__
  |  |  |  |  ------------------
  |  |  |  |  228|  1.08k|	  gsize __n = (gsize) (n_structs);			\
  |  |  |  |  229|  1.08k|	  gsize __s = sizeof (struct_type);			\
  |  |  |  |  230|  1.08k|	  gpointer __p;						\
  |  |  |  |  231|  1.08k|	  if (__s == 1)						\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (231:8): [True: 0, False: 1.08k]
  |  |  |  |  ------------------
  |  |  |  |  232|  1.08k|	    __p = g_##func (__n);				\
  |  |  |  |  233|  1.08k|	  else if (__builtin_constant_p (__n) &&		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (233:13): [True: 0, False: 1.08k]
  |  |  |  |  ------------------
  |  |  |  |  234|  1.08k|	           (__s == 0 || __n <= G_MAXSIZE / __s))	\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (234:14): [True: 0, False: 0]
  |  |  |  |  |  Branch (234:26): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  235|  1.08k|	    __p = g_##func (__n * __s);				\
  |  |  |  |  236|  1.08k|	  else							\
  |  |  |  |  237|  1.08k|	    __p = g_##func##_n (__n, __s);			\
  |  |  |  |  238|  1.08k|	  __p;							\
  |  |  |  |  239|  1.08k|	}))
  |  |  ------------------
  ------------------
 1353|  5.74k|            for (i = 0; i < count; i++) {
  ------------------
  |  Branch (1353:25): [True: 4.66k, False: 1.08k]
  ------------------
 1354|  4.66k|                const char *cert = args;
 1355|  4.66k|                args = strpbrk(args, ",)");
 1356|  4.66k|                vreaderOpt->cert_name[i] = g_strndup(cert, args - cert);
 1357|  4.66k|                args = strip(args+1);
 1358|  4.66k|            }
 1359|  1.08k|            if (*args == ')') {
  ------------------
  |  Branch (1359:17): [True: 66, False: 1.02k]
  ------------------
 1360|     66|                args++;
 1361|     66|            }
 1362|  1.08k|            opts->vreader_count++;
 1363|       |        /* use_hw= */
 1364|  1.26k|        } else if (strncmp(args, "use_hw=", 7) == 0) {
  ------------------
  |  Branch (1364:20): [True: 521, False: 747]
  ------------------
 1365|    521|            args = strip(args+7);
 1366|    521|            if (*args == '0' || *args == 'N' || *args == 'n' || *args == 'F') {
  ------------------
  |  Branch (1366:17): [True: 66, False: 455]
  |  Branch (1366:33): [True: 66, False: 389]
  |  Branch (1366:49): [True: 66, False: 323]
  |  Branch (1366:65): [True: 67, False: 256]
  ------------------
 1367|    265|                opts->use_hw = USE_HW_NO;
 1368|    265|            } else if (strncmp(args, "removable", 9) == 0) {
  ------------------
  |  Branch (1368:24): [True: 66, False: 190]
  ------------------
 1369|     66|                opts->use_hw = USE_HW_REMOVABLE;
 1370|    190|            } else {
 1371|    190|                opts->use_hw = USE_HW_YES;
 1372|    190|            }
 1373|    521|            args = find_blank(args);
 1374|       |        /* hw_type= */
 1375|    747|        } else if (strncmp(args, "hw_type=", 8) == 0) {
  ------------------
  |  Branch (1375:20): [True: 60, False: 687]
  ------------------
 1376|     60|            args = strip(args+8);
 1377|     60|            opts->hw_card_type = vcard_emul_type_from_string(args);
 1378|     60|            if (opts->hw_card_type == VCARD_EMUL_NONE) {
  ------------------
  |  Branch (1378:17): [True: 59, False: 1]
  ------------------
 1379|     59|                fprintf(stderr, "Error: invalid smartcard type '%s'.\n",
 1380|     59|                        args);
 1381|     59|                goto fail;
 1382|     59|            }
 1383|      1|            args = find_blank(args);
 1384|       |        /* hw_params= */
 1385|    687|        } else if (strncmp(args, "hw_params=", 10) == 0) {
  ------------------
  |  Branch (1385:20): [True: 30, False: 657]
  ------------------
 1386|     30|            const char *params;
 1387|       |
 1388|     30|            if (opts->hw_type_params != NULL) {
  ------------------
  |  Branch (1388:17): [True: 1, False: 29]
  ------------------
 1389|      1|                fprintf(stderr, "Error: redefinition of hw_params= is not allowed.\n");
 1390|      1|                goto fail;
 1391|      1|            }
 1392|     29|            args = strip(args+10);
 1393|     29|            params = args;
 1394|     29|            args = find_blank(args);
 1395|     29|            opts->hw_type_params = g_strndup(params, args-params);
 1396|       |        /* db="/data/base/path" */
 1397|    657|        } else if (strncmp(args, "db=", 3) == 0) {
  ------------------
  |  Branch (1397:20): [True: 25, False: 632]
  ------------------
 1398|     25|            const char *db;
 1399|       |
 1400|     25|            if (opts->nss_db != NULL) {
  ------------------
  |  Branch (1400:17): [True: 1, False: 24]
  ------------------
 1401|      1|                fprintf(stderr, "Error: redefinition of db= is not allowed.\n");
 1402|      1|                goto fail;
 1403|      1|            }
 1404|     24|            args = strip(args+3);
 1405|     24|            if (*args != '"') {
  ------------------
  |  Branch (1405:17): [True: 21, False: 3]
  ------------------
 1406|     21|                fprintf(stderr, "Error: you must quote the file path.\n");
 1407|     21|                goto fail;
 1408|     21|            }
 1409|      3|            args++;
 1410|      3|            db = args;
 1411|      3|            args = strpbrk(args, "\"\n");
 1412|      3|            if (args == NULL) {
  ------------------
  |  Branch (1412:17): [True: 1, False: 2]
  ------------------
 1413|      1|                fprintf(stderr, "Error: invalid db argument.\n");
 1414|      1|                goto fail;
 1415|      1|            }
 1416|      2|            opts->nss_db = g_strndup(db, args-db);
 1417|      2|            if (*args != 0) {
  ------------------
  |  Branch (1417:17): [True: 2, False: 0]
  ------------------
 1418|      2|                args++;
 1419|      2|            }
 1420|    632|        } else if (strncmp(args, "nssemul", 7) == 0) {
  ------------------
  |  Branch (1420:20): [True: 256, False: 376]
  ------------------
 1421|    256|            opts->hw_card_type = VCARD_EMUL_CAC;
 1422|    256|            opts->use_hw = USE_HW_YES;
 1423|    256|            args = find_blank(args + 7);
 1424|       |#if defined(ENABLE_PCSC)
 1425|       |        } else if (strncmp(args, "passthru", 8) == 0) {
 1426|       |            opts->hw_card_type = VCARD_EMUL_PASSTHRU;
 1427|       |            opts->use_hw = USE_HW_YES;
 1428|       |            args = find_blank(args + 8);
 1429|       |#endif
 1430|    376|        } else {
 1431|    376|            fprintf(stderr, "Error: Unknown smartcard specification.\n");
 1432|    376|            goto fail;
 1433|    376|        }
 1434|  2.48k|    } while (*args != 0);
  ------------------
  |  Branch (1434:14): [True: 1.99k, False: 302]
  ------------------
 1435|       |
 1436|    302|    return opts;
 1437|       |
 1438|    588|fail:
 1439|       |    /* Clean up what was allocated above on failure */
 1440|  1.04k|    for (i = 0; i < opts->vreader_count; i++) {
  ------------------
  |  Branch (1440:17): [True: 460, False: 588]
  ------------------
 1441|    460|        g_free(opts->vreader[i].name);
 1442|    460|        g_free(opts->vreader[i].vname);
 1443|    460|        g_free(opts->vreader[i].type_params);
 1444|  2.24k|        for (j = 0; j < opts->vreader[i].cert_count; j++) {
  ------------------
  |  Branch (1444:21): [True: 1.78k, False: 460]
  ------------------
 1445|  1.78k|            g_free(opts->vreader[i].cert_name[j]);
 1446|  1.78k|        }
 1447|    460|        g_free(opts->vreader[i].cert_name);
 1448|    460|    }
 1449|    588|    g_free(opts->vreader);
 1450|    588|    g_free(opts->hw_type_params);
 1451|    588|    g_free(opts->nss_db);
 1452|    588|    return NULL;
 1453|    890|}
vcard_emul_nss.c:strip:
 1245|  15.1k|{
 1246|  18.1k|    for (; *str && isspace(*str); str++) {
  ------------------
  |  Branch (1246:12): [True: 17.9k, False: 228]
  ------------------
 1247|  2.98k|    }
 1248|  15.1k|    return str;
 1249|  15.1k|}
vcard_emul_nss.c:count_tokens:
 1229|  1.08k|{
 1230|  1.08k|    int count = 0;
 1231|       |
 1232|  4.95k|    for (; *str; str++) {
  ------------------
  |  Branch (1232:12): [True: 4.95k, False: 0]
  ------------------
 1233|  4.95k|        if (*str == token) {
  ------------------
  |  Branch (1233:13): [True: 3.57k, False: 1.37k]
  ------------------
 1234|  3.57k|            count++;
 1235|  3.57k|        }
 1236|  4.95k|        if (*str == token_end) {
  ------------------
  |  Branch (1236:13): [True: 1.08k, False: 3.86k]
  ------------------
 1237|  1.08k|            break;
 1238|  1.08k|        }
 1239|  4.95k|    }
 1240|  1.08k|    return count;
 1241|  1.08k|}
vcard_emul_nss.c:find_blank:
 1253|    807|{
 1254|  2.92k|    for (; *str && !isspace(*str); str++) {
  ------------------
  |  Branch (1254:12): [True: 2.71k, False: 209]
  |  Branch (1254:20): [True: 2.11k, False: 598]
  ------------------
 1255|  2.11k|    }
 1256|    807|    return str;
 1257|    807|}

vcard_emul_type_from_string:
   57|  1.20k|{
   58|  1.20k|     if (strcasecmp(type_string, "CAC") == 0) {
  ------------------
  |  Branch (58:10): [True: 1.10k, False: 98]
  ------------------
   59|  1.10k|        return VCARD_EMUL_CAC;
   60|  1.10k|     }
   61|       |#ifdef ENABLE_PCSC
   62|       |     if (strcasecmp(type_string, "PASSTHRU") == 0) {
   63|       |        return VCARD_EMUL_PASSTHRU;
   64|       |     }
   65|       |#endif
   66|     98|     return VCARD_EMUL_NONE;
   67|  1.20k|}

