oss-fuzz/projects/ibmswtpm2/no_writes.patch

135 lines
3.4 KiB
Diff
Raw Normal View History

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 $@