tools: specify parameter size limits for LPC

Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: Ic7049ffc2a3c4e7dad3356e11f48f6e5ed8eeca1
diff --git a/tools/lpc.cpp b/tools/lpc.cpp
index 7a5faa2..3d6bc4b 100644
--- a/tools/lpc.cpp
+++ b/tools/lpc.cpp
@@ -28,8 +28,8 @@
     LpcRegion host_lpc_buf;
 
     /* TODO: Remove hard-coded configuration used with test machine. */
-    host_lpc_buf.address = 0xfedc1000;
-    host_lpc_buf.length = 0x1000;
+    host_lpc_buf.address = address;
+    host_lpc_buf.length = length;
 
     std::vector<std::uint8_t> payload(sizeof(host_lpc_buf));
     std::memcpy(payload.data(), &host_lpc_buf, sizeof(host_lpc_buf));
diff --git a/tools/lpc.hpp b/tools/lpc.hpp
index 7343648..32e1d8c 100644
--- a/tools/lpc.hpp
+++ b/tools/lpc.hpp
@@ -22,7 +22,7 @@
 {
   public:
     LpcDataHandler(ipmiblob::BlobInterface* blob, HostIoInterface* io,
-                   long address, long length,
+                   std::uint32_t address, std::uint32_t length,
                    const internal::Sys* sys = &internal::sys_impl) :
         blob(blob),
         io(io), address(address), length(length), sys(sys){};
@@ -36,8 +36,8 @@
   private:
     ipmiblob::BlobInterface* blob;
     HostIoInterface* io;
-    long address;
-    long length;
+    std::uint32_t address;
+    std::uint32_t length;
     const internal::Sys* sys;
 };
 
diff --git a/tools/main.cpp b/tools/main.cpp
index ff00dd4..c944899 100644
--- a/tools/main.cpp
+++ b/tools/main.cpp
@@ -33,6 +33,7 @@
 #include <ipmiblob/blob_handler.hpp>
 #include <ipmiblob/ipmi_handler.hpp>
 #include <iterator>
+#include <limits>
 #include <memory>
 #include <string>
 #include <vector>
@@ -78,6 +79,8 @@
     char* valueEnd = nullptr;
     long address = 0;
     long length = 0;
+    std::uint32_t hostAddress = 0;
+    std::uint32_t hostLength = 0;
 
     while (1)
     {
@@ -133,6 +136,13 @@
                     usage(argv[0]);
                     exit(EXIT_FAILURE);
                 }
+                if (address > std::numeric_limits<std::uint32_t>::max())
+                {
+                    std::fprintf(stderr, "Address beyond 32-bit limit.\n");
+                    usage(argv[0]);
+                    exit(EXIT_FAILURE);
+                }
+                hostAddress = static_cast<std::uint32_t>(address);
                 break;
             case 'l':
                 length = std::strtol(&optarg[0], &valueEnd, 0);
@@ -141,6 +151,13 @@
                     usage(argv[0]);
                     exit(EXIT_FAILURE);
                 }
+                if (length > std::numeric_limits<std::uint32_t>::max())
+                {
+                    std::fprintf(stderr, "Length beyond 32-bit limit.\n");
+                    usage(argv[0]);
+                    exit(EXIT_FAILURE);
+                }
+                hostLength = static_cast<std::uint32_t>(length);
                 break;
             default:
                 usage(argv[0]);
@@ -177,13 +194,13 @@
         }
         else if (interface == IPMILPC)
         {
-            if (address == 0 || length == 0)
+            if (hostAddress == 0 || hostLength == 0)
             {
                 std::fprintf(stderr, "Address or Length were 0\n");
                 exit(EXIT_FAILURE);
             }
             handler = std::make_unique<host_tool::LpcDataHandler>(
-                &blob, &devmem, address, length);
+                &blob, &devmem, hostAddress, hostLength);
         }
         else if (interface == IPMIPCI)
         {
diff --git a/tools/test/tools_lpc_unittest.cpp b/tools/test/tools_lpc_unittest.cpp
index 4a18273..ef8e93e 100644
--- a/tools/test/tools_lpc_unittest.cpp
+++ b/tools/test/tools_lpc_unittest.cpp
@@ -18,7 +18,7 @@
     ipmiblob::BlobInterfaceMock blobMock;
     HostIoInterfaceMock ioMock;
 
-    LpcDataHandler handler(&blobMock, &ioMock, 0, 0, &sysMock);
+    LpcDataHandler handler(&blobMock, &ioMock, 0xfedc1000, 0x1000, &sysMock);
     std::uint16_t session = 0xbeef;
     std::string filePath = "/asdf";