Coverage Report

Created: 2025-10-13 06:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ibmswtpm2/src/fuzzer.cc
Line
Count
Source
1
#include "TpmBuildSwitches.h"
2
#include <stdlib.h>
3
#include <stdio.h>
4
#include <stdint.h>
5
#include <ctype.h>
6
#include <string.h>
7
#ifdef TPM_WINDOWS
8
#include <windows.h>
9
#include <winsock.h>
10
#endif
11
12
extern "C" {
13
#include "Implementation.h" /* kgold */
14
#include "TpmTcpProtocol.h"
15
#include "Manufacture_fp.h"
16
#include "Platform_fp.h"
17
#include "Simulator_fp.h"
18
#ifdef TPM_WINDOWS
19
#include "TcpServer_fp.h"
20
#endif
21
#ifdef TPM_POSIX
22
#include "TcpServerPosix_fp.h"
23
#endif
24
}
25
26
246
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
27
246
  int pipefd[2];
28
29
246
  if (Data == NULL || Size == 0) {
30
0
    return 0;
31
0
  }
32
33
246
  if (pipe(pipefd) == -1) {
34
0
    perror("creating pipe");
35
0
    exit(EXIT_FAILURE);
36
0
  }
37
38
246
  if (write(pipefd[1], Data, Size) != (ssize_t)Size) {
39
0
    perror("write to pipe");
40
0
    exit(EXIT_FAILURE);
41
0
  }
42
43
246
  close(pipefd[1]);
44
45
246
  _plat__NVEnable(NULL);
46
246
  if (TPM_Manufacture(1) != 0) {
47
0
    dprintf(STDERR_FILENO, "[FAILED] manufacturing\n");
48
0
    exit(1);
49
0
  }
50
  // Coverage test - repeated manufacturing attempt
51
246
  if (TPM_Manufacture(0) != 1) {
52
0
    dprintf(STDERR_FILENO, "[FAILED] Coverage test - repeated manufacturing attempt\n");
53
0
    exit(2);
54
0
  }
55
  // Coverage test - re-manufacturing
56
246
  TPM_TearDown();
57
246
  if (TPM_Manufacture(1) != 0) {
58
0
    dprintf(STDERR_FILENO, "[FAILED] Coverage test - re-manufacturing\n");
59
0
    exit(3);
60
0
  }
61
  // Disable NV memory
62
246
  _plat__NVDisable();
63
  /* power on the TPM kgold MS simulator comes up powered off */
64
246
  _rpc__Signal_PowerOn(FALSE);
65
246
  _rpc__Signal_NvOn();
66
67
  // From TSS2 MSSIM simulator_setup
68
  // tcti_platform_command (tctiContext, MS_SIM_POWER_ON);
69
246
  _rpc__Signal_PowerOn(FALSE);
70
  // tcti_platform_command (tctiContext, MS_SIM_NV_ON);
71
246
  _rpc__Signal_NvOn();
72
73
246
  TpmServer(pipefd[0]);
74
75
246
  close(pipefd[0]);
76
77
246
  return 0;
78
246
}