manager: add hard-coded read checks
The host-client cannot try to read back more than this number of bytes
without hitting a memory overflow in phosphor-host-ipmid. The method we
can call to dynamically receive that number isn't currently linking out
of the userlayer library.
Note: Once the configure_ac can find and provide the userlayer library
from phosphor-host-ipmid, we can remove the hard-coded 64 and 0xe.
Change-Id: I08f6bb59ce44279f76a494dccaa477ae75d532c4
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/test/manager_read_unittest.cpp b/test/manager_read_unittest.cpp
index 1d40f5d..73e198b 100644
--- a/test/manager_read_unittest.cpp
+++ b/test/manager_read_unittest.cpp
@@ -60,7 +60,7 @@
uint16_t sess = 1;
uint32_t ofs = 0x54;
- uint32_t requested = 0x100;
+ uint32_t requested = 0x10;
uint16_t flags = OpenFlags::read;
std::string path = "/asdf/asdf";
std::vector<uint8_t> data = {0x12, 0x14, 0x15, 0x16};
@@ -75,4 +75,35 @@
EXPECT_EQ(data.size(), result.size());
EXPECT_EQ(result, data);
}
+
+TEST(ManagerReadTest, ReadTooManyBytesTruncates)
+{
+ // For now, the hard-coded maximum transfer size is 64 bytes on read
+ // commands, due to a hard-coded buffer in ipmid among other future
+ // challenges.
+
+ BlobManager mgr;
+ std::unique_ptr<BlobMock> m1 = std::make_unique<BlobMock>();
+ auto m1ptr = m1.get();
+ EXPECT_TRUE(mgr.registerHandler(std::move(m1)));
+
+ uint16_t sess = 1;
+ uint32_t ofs = 0x54;
+ uint32_t requested = 0x100;
+ uint16_t flags = OpenFlags::read;
+ std::string path = "/asdf/asdf";
+ std::vector<uint8_t> data = {0x12, 0x14, 0x15, 0x16};
+
+ EXPECT_CALL(*m1ptr, canHandleBlob(path)).WillOnce(Return(true));
+ EXPECT_CALL(*m1ptr, open(_, flags, path)).WillOnce(Return(true));
+ EXPECT_TRUE(mgr.open(flags, path, &sess));
+
+ EXPECT_CALL(*m1ptr, read(sess, ofs, maximumReadSize))
+ .WillOnce(Return(data));
+
+ std::vector<uint8_t> result = mgr.read(sess, ofs, requested);
+ EXPECT_EQ(data.size(), result.size());
+ EXPECT_EQ(result, data);
+}
+
} // namespace blobs