]> git.proxmox.com Git - efi-boot-shim.git/blame - fuzz-csv.c
bump version to 15.8-1+pmx1
[efi-boot-shim.git] / fuzz-csv.c
CommitLineData
fd2d9f03
SM
1// SPDX-License-Identifier: BSD-2-Clause-Patent
2/*
3 * test-csv.c - test our csv parser
4 */
5
6#ifndef SHIM_UNIT_TEST
7#define SHIM_UNIT_TEST
8#endif
9#include "shim.h"
10
11#include <stdio.h>
12
13int
14test_csv_simple_fuzz(char *random_bin, size_t random_bin_len)
15{
16 list_t entry_list;
17 size_t i;
18 char *current, *end;
19 list_t *pos = NULL;
20 EFI_STATUS efi_status;
21
22 INIT_LIST_HEAD(&entry_list);
23
24 current = &random_bin[0];
25 current = current + 1 - 1;
26 end = current + random_bin_len - 1;
27 *end = '\0';
28
29 efi_status = parse_csv_data(current, end, 7, &entry_list);
30 if (efi_status != EFI_SUCCESS)
31 return 0;
32 if (list_size(&entry_list) <= 1)
33 goto fail;
34
35 i = 0;
36 list_for_each(pos, &entry_list) {
37 struct csv_row *csv_row;
38
39 csv_row = list_entry(pos, struct csv_row, list);
40 i++;
41 }
42
43 free_csv_list(&entry_list);
44
45 return 0;
46fail:
47 free_csv_list(&entry_list);
48 return -1;
49}
50
51int
52LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
53{
54 int rc;
55 uint8_t *data_copy;
56
57 if (size < 1)
58 return 0;
59
60 data_copy = malloc(size);
61 if (!data_copy)
62 return -1;
63
64 memcpy(data_copy, data, size);
65 rc = test_csv_simple_fuzz((char *)data_copy, size);
66 free(data_copy);
67
68 return rc; // Values other than 0 and -1 are reserved for future use.
69}
70
71// vim:fenc=utf-8:tw=75:noet