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