Coverage Report

Created: 2024-05-20 06:10

/src/fuzz_hci.c
Line
Count
Source
1
/* Copyright 2022 Google LLC
2
Licensed under the Apache License, Version 2.0 (the "License");
3
you may not use this file except in compliance with the License.
4
You may obtain a copy of the License at
5
      http://www.apache.org/licenses/LICENSE-2.0
6
Unless required by applicable law or agreed to in writing, software
7
distributed under the License is distributed on an "AS IS" BASIS,
8
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9
See the License for the specific language governing permissions and
10
limitations under the License.
11
*/
12
#include <config.h>
13
14
#include <stdint.h>
15
#include <string.h>
16
#include <stdlib.h>
17
#include <syslog.h>
18
19
#include "bluetooth.h"
20
#include "sdp.h"
21
#include "sdp_lib.h"
22
#include "hci_lib.h"
23
24
25
2.46k
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
26
2.46k
  int to_copy = size;
27
2.46k
  uint8_t features[8];
28
29
2.46k
  if (size > 8) {
30
2.45k
    to_copy = 8;
31
2.45k
  }
32
33
2.46k
  char *null_terminated = malloc(to_copy+1);
34
2.46k
  memcpy(null_terminated, data, to_copy);
35
2.46k
  null_terminated[to_copy] = '\0';
36
/*
37
  char *tmp = lmp_featurestostr(features, null_terminated, to_copy);
38
  if (tmp) {
39
    free(tmp);
40
  }
41
*/
42
2.46k
  char *tmp = NULL;
43
44
2.46k
  size -= to_copy;
45
2.46k
  data += to_copy;
46
47
  /*
48
  uint8_t cmds[64];
49
  bzero(cmds, 64);
50
  for (int i = 0; i < 64 && i < size; i++) {
51
    cmds[i] = data[i];
52
  }
53
  tmp = hci_commandstostr(cmds, NULL, 0);
54
  if (tmp) {
55
    free(tmp);
56
  }
57
  */
58
2.46k
  if (size > 4) {
59
2.45k
    uint16_t id = *(uint16_t*)data;
60
2.45k
    bt_compidtostr(id);
61
2.45k
  }
62
63
2.46k
  free(null_terminated);
64
2.46k
  return 0;
65
2.46k
}