aboutsummaryrefslogtreecommitdiff
path: root/projects/ibmswtpm2/no_writes.patch
blob: ca8d7c69937b3d756840604d253d365d266df2dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
diff --git a/CompilerDependencies.h b/CompilerDependencies.h
index b6c0577..c89b125 100644
--- a/CompilerDependencies.h
+++ b/CompilerDependencies.h
@@ -146,7 +146,7 @@
 #ifndef NOT_REFERENCED
 #   define  NOT_REFERENCED(x) (x = x)
 #endif
-#ifdef _POSIX_
+#ifdef IS_POSIX
 typedef int SOCKET;
 #endif
 // #ifdef TPM_POSIX
diff --git a/GpMacros.h b/GpMacros.h
index ff4251d..3494b55 100644
--- a/GpMacros.h
+++ b/GpMacros.h
@@ -84,7 +84,7 @@
 #   define TEST_HASH(alg)
 #endif // SELF_TEST
 /* 5.11.3	For Failures */
-#if defined _POSIX_
+#if defined IS_POSIX
 #   define FUNCTION_NAME        0
 #else
 #   define FUNCTION_NAME        __FUNCTION__
diff --git a/TPMCmds.c b/TPMCmds.c
index 173dcf7..0805575 100644
--- a/TPMCmds.c
+++ b/TPMCmds.c
@@ -110,7 +110,12 @@ Usage(
 /* This is the main entry point for the simulator. */
 /* It registers the interface and starts listening for clients */
 int
-main(
+#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
+main
+#else
+tpm_server_main
+#endif /* FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */
+(
      int              argc,
      char            *argv[]
      )
diff --git a/TcpServerPosix.c b/TcpServerPosix.c
index be48607..8dfcbea 100644
--- a/TcpServerPosix.c
+++ b/TcpServerPosix.c
@@ -721,9 +721,11 @@ TpmServer(
 			    memcpy(&CommandResponseSizes.largestResponse,
 				   &OutputBuffer[6], sizeof(UINT32));
 			}
+#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
 		    ok = WriteVarBytes(s,
 				       (char*) OutBuffer.Buffer,
 				       OutBuffer.BufferSize);
+#endif /* FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */
 		    if(!ok)
 			return TRUE;
 		    break;
@@ -737,9 +739,11 @@ TpmServer(
 			    printf("Unsupported client version (0).\n");
 			    return TRUE;
 			}
+#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
 		    ok &= WriteUINT32(s, ServerVersion);
 		    ok &= WriteUINT32(s,
 				      tpmInRawMode | tpmPlatformAvailable | tpmSupportsPP);
+#endif /* FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */
 		    break;
 		    
 		  case TPM_SET_ALTERNATIVE_RESULT:
@@ -760,7 +764,9 @@ TpmServer(
 		    printf("Unrecognized TPM interface command %08x\n", Command);
 		    return TRUE;
 		}
+#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
 	    ok = WriteUINT32(s,0);
+#endif /* FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */
 	    if(!ok)
 		return TRUE;
 	}
diff --git a/makefile b/makefile
index cc3e410..c10ba5a 100644
--- a/makefile
+++ b/makefile
@@ -40,16 +40,16 @@
 
 
-CC = /usr/bin/gcc
 
-CCFLAGS = -Wall  			\
+CCFLAGS = $(CFLAGS) -Wall  			\
 	-Wmissing-declarations -Wmissing-prototypes -Wnested-externs \
-	-Werror -Wsign-compare \
+	-Wsign-compare \
 	 -c -ggdb -O0 			\
 	-DTPM_POSIX			\
-	-D_POSIX_			\
+	-DIS_POSIX			\
 	-DTPM_NUVOTON			\
 	-I../utils			\
-	-I.
+	-I. \
+	-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
 
 LNFLAGS = -ggdb 			\
 	-DTPM_POSIX			\
@@ -57,7 +60,8 @@ LNFLAGS = -ggdb 			\
 	-lcrypto			\
 	-lpthread			\
 	-lrt				\
-	-I.
+	-I. \
+	-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION $(LIB_FUZZING_ENGINE)
 
 all:	tpm_server
 
@@ -75,9 +79,14 @@ TcpServerPosix.o	: $(HEADERS)
 tpm_server:	$(OBJFILES)
 		$(CC) $(OBJFILES) $(LNFLAGS) -o tpm_server
 
+fuzz_tpm_server:	$(OBJFILES) fuzzer.o
+		$(CXX) $(CXXFLAGS) fuzzer.o $(OBJFILES) $(LNFLAGS) -o fuzz_tpm_server
+
 clean:		
-		rm -f *.o tpm_server *~
+		rm -f *.o tpm_server fuzz_tpm_server *~
 
 %.o:		%.c
 		$(CC) $(CCFLAGS) $< -o $@
 
+%.o:		%.cc
+		$(CXX) $(CXXFLAGS) $(CCFLAGS) $(LIB_FUZZING_ENGINE) $< -o $@