Move CheckOverflow.c from sapi_util to common.

These functions are no longer required by the SAPI / marshalling code
but they are needed by the resourcemgr. This removes symbols from the
sapi library that we don't want to expose.

Signed-off-by: Philip Tricca <philip.b.tricca@intel.com>
diff --git a/Makefile.am b/Makefile.am
index f3d09b2..c71e6cc 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -41,7 +41,6 @@
 # unit tests
 if UNIT
 TESTS_UNIT  = \
-    test/unit/CheckOverflow \
     test/unit/CommonPreparePrologue \
     test/unit/CopyCommandHeader \
     test/unit/getcommands-malloc-mock \
@@ -118,20 +117,12 @@
 test_unit_marshal_TPM2B_simple_LDADD   = $(CMOCKA_LIBS) $(libmarshal)
 test_unit_marshal_TPM2B_simple_SOURCES = \
     sysapi/sysapi_util/changeEndian.c \
-    sysapi/sysapi_util/checkoverflow.c \
     sysapi/sysapi_util/CopySessionData.c \
     sysapi/sysapi_util/marshal_simple_tpm2b.c \
     sysapi/sysapi_util/unmarshal_simple_tpm2b.c \
     sysapi/sysapi_util/unmarshal_simple_tpm2b_no_size_check.c \
     test/unit/marshal-TPM2B-simple.c
 
-test_unit_CheckOverflow_CFLAGS  = $(CMOCKA_CFLAGS) \
-    -I$(srcdir)/include -I$(srcdir)/include/sapi -I$(srcdir)/sysapi/include/
-test_unit_CheckOverflow_LDADD   = $(CMOCKA_LIBS)
-test_unit_CheckOverflow_SOURCES = \
-    sysapi/sysapi_util/checkoverflow.c \
-    test/unit/CheckOverflow.c
-
 test_unit_UINT8_marshal_CFLAGS  = $(CMOCKA_CFLAGS) -I$(srcdir)/include
 test_unit_UINT8_marshal_LDADD   = $(CMOCKA_LIBS) $(libmarshal)
 test_unit_UINT8_marshal_SOURCES = test/unit/UINT8-marshal.c
diff --git a/sysapi/sysapi_util/checkoverflow.c b/common/checkoverflow.c
similarity index 100%
rename from sysapi/sysapi_util/checkoverflow.c
rename to common/checkoverflow.c
diff --git a/common/checkoverflow.h b/common/checkoverflow.h
new file mode 100644
index 0000000..b3dbd92
--- /dev/null
+++ b/common/checkoverflow.h
@@ -0,0 +1,19 @@
+#ifndef CHECKOVERFLOW_H
+#define CHECKOVERFLOW_H
+
+TSS2_RC
+CheckOverflow (
+    UINT8   *buffer,
+    UINT32   bufferSize,
+    UINT8   *nextData,
+    UINT32   size
+    );
+
+TSS2_RC
+CheckDataPointers (
+    UINT8   *buffer,
+    UINT8  **nextData
+    );
+
+#endif /* CHECKOVERFLOW_H */
+
diff --git a/resourcemgr/resourcemgr.c b/resourcemgr/resourcemgr.c
index 493a0e8..9d13138 100755
--- a/resourcemgr/resourcemgr.c
+++ b/resourcemgr/resourcemgr.c
@@ -39,6 +39,7 @@
 #include "sysapi_util.h"
 #include "syscontext.h"
 #include "debug.h"
+#include "checkoverflow.h"
 
 #if defined(__linux__) || defined(__unix__)
 
diff --git a/sysapi/include/sys_api_marshalUnmarshal.h b/sysapi/include/sys_api_marshalUnmarshal.h
index 13ce116..be6bc35 100644
--- a/sysapi/include/sys_api_marshalUnmarshal.h
+++ b/sysapi/include/sys_api_marshalUnmarshal.h
@@ -142,10 +142,6 @@
 void Marshal_TPMS_EMPTY( TSS2_SYS_CONTEXT *sysContext, TPMS_EMPTY *empty );
 void Unmarshal_TPMS_EMPTY( TSS2_SYS_CONTEXT *sysContext, TPMS_EMPTY *empty );
 
-TSS2_RC CheckOverflow( UINT8 *buffer, UINT32 bufferSize, UINT8 *nextData, UINT32 size );
-TSS2_RC CheckDataPointers( UINT8 *buffer, UINT8 **nextData );
-
-
 // Macro for unmarshalling/marshalling in SYSAPI code.  We needed access to generic base functions in resource manager and
 // other places
 #define UNMARSHAL_SIMPLE_TPM2B( sysContext, value ) \
diff --git a/test/unit/CheckOverflow.c b/test/unit/CheckOverflow.c
deleted file mode 100644
index 883b341..0000000
--- a/test/unit/CheckOverflow.c
+++ /dev/null
@@ -1,149 +0,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-
-#include <setjmp.h>
-#include <cmocka.h>
-#include <sapi/tpm20.h>
-
-#include "sys_api_marshalUnmarshal.h"
-#include "sysapi_util.h"
-
-/**
- * This tests the "common case" for the CheckOverflow. We define this as:
- * nexData > buffer, nextData + size <= bufferSize.
- */
-void
-CheckOverflow_good (void **state)
-{
-    TSS2_RC rc;
-    UINT8 *buffer = 0x0, *nextData = (UINT8*)0x2;
-    UINT32 bufferSize = 0x4, size = 0x2;
-
-    rc = CheckOverflow (buffer, bufferSize, nextData, size);
-    assert_int_equal (rc, TSS2_RC_SUCCESS);
-}
-/**
- * This tests an edge case where nextData == buffer and bufferSize == size.
- * CheckOverflow should be successful in this case.
- */
-void
-CheckOverflow_whole_buffer (void **state)
-{
-    TSS2_RC rc;
-    UINT8 *buffer = 0x0, *nextData = buffer;
-    UINT32 bufferSize = 0x4, size = 0x4;
-
-    rc = CheckOverflow (buffer, bufferSize, nextData, size);
-    assert_int_equal (rc, TSS2_RC_SUCCESS);
-}
-/**
- * Test the case that CheckOverflow is designed to catch. Specifically this
- * is the case where nextData > buffer, nextData + size > bufferSize
- */
-void
-CheckOverflow_overflow(void **state)
-{
-    TSS2_RC rc;
-    UINT8 *buffer = (UINT8*)0x1, *nextData = (UINT8*)0x4;
-    UINT32 bufferSize = 0x5, size = 0x6;
-
-    rc = CheckOverflow (buffer, bufferSize, nextData, size);
-    assert_int_equal (rc, TSS2_SYS_RC_INSUFFICIENT_CONTEXT);
-}
-/**
- * Test an edge case for the CheckOverflow function: buffer == nextData,
- * nextData + size < bufferSize.
- */
-void
-CheckOverflow_buf_next_equal (void **state)
-{
-    TSS2_RC rc;
-    UINT8 *buffer = (UINT8*)0x5, *nextData = buffer;
-    UINT32 bufferSize = 0x5, size = 0x1;
-
-    rc = CheckOverflow (buffer, bufferSize, nextData, size);
-    assert_int_equal (rc, TSS2_RC_SUCCESS);
-}
-/**
- * This tests another edge case: nextData in this case is beyond the end of
- * the provided buffer.
- */
-void
-CheckOverflow_nextData_gt_buffer_end (void **state)
-{
-    TSS2_RC rc;
-    UINT32 bufferSize = 0x1, size = 0x5;
-    UINT8 *buffer = (UINT8*)0x5, *nextData = buffer + size;
-
-    rc = CheckOverflow (buffer, bufferSize, nextData, size);
-    assert_int_equal (rc, TSS2_SYS_RC_INSUFFICIENT_CONTEXT);
-}
-/**
- * Pass the CheckDataPointers function a NULL first parameter.
- * This should return a bad reference error.
- */
-void
-CheckDataPointers_null_buffer (void **state)
-{
-    TSS2_RC rc;
-    UINT8 *buffer = NULL, *nextData = (UINT8*)5;
-
-    rc = CheckDataPointers (buffer, &nextData);
-    assert_int_equal (rc, TSS2_SYS_RC_BAD_REFERENCE);
-}
-/**
- * Pass the CheckDataPointers function a reference to a null pointer
- * in the second parameter. This should result in a bad reference RC.
- */
-void
-CheckDataPointers_null_nextData (void **state)
-{
-    TSS2_RC rc;
-    UINT8 *buffer = (UINT8*)5, *nextData = NULL;
-
-    rc = CheckDataPointers (buffer, &nextData);
-    assert_int_equal (rc, TSS2_SYS_RC_BAD_REFERENCE);
-}
-/**
- * Pass the CheckDataPointers function a NULL second paraemter. This should
- * result in a bad reference RC.
- */
-void
-CheckDataPointers_null_nextData_ptr (void **state)
-{
-    TSS2_RC rc;
-    UINT8 *buffer = (UINT8*)5, **nextData = NULL;
-
-    rc = CheckDataPointers (buffer, nextData);
-    assert_int_equal (rc, TSS2_SYS_RC_BAD_REFERENCE);
-}
-/**
- * Test an error case where nextData < buffer. Regardless of the size of the
- * data buffer this should fail.
- */
-void
-CheckDataPointers_nextData_lt_buffer_start (void **state)
-{
-    TSS2_RC rc;
-    UINT8 *buffer = (UINT8*)0x5, *nextData = buffer - 1;
-
-    rc = CheckDataPointers (buffer, &nextData);
-    assert_int_equal (rc, TSS2_SYS_RC_BAD_REFERENCE);
-}
-
-int
-main (void)
-{
-    const UnitTest tests [] = {
-        unit_test (CheckOverflow_good),
-        unit_test (CheckOverflow_whole_buffer),
-        unit_test (CheckOverflow_overflow),
-        unit_test (CheckOverflow_buf_next_equal),
-        unit_test (CheckOverflow_nextData_gt_buffer_end),
-        unit_test (CheckDataPointers_null_buffer),
-        unit_test (CheckDataPointers_null_nextData),
-        unit_test (CheckDataPointers_null_nextData_ptr),
-        unit_test (CheckDataPointers_nextData_lt_buffer_start),
-    };
-    return run_tests (tests);
-}