From 86c87f55de9bb69f6e49c6203ffb0e12947ea7cf Mon Sep 17 00:00:00 2001 From: Patrick Venture Date: Fri, 1 Feb 2019 14:44:15 -0800 Subject: 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 --- test/manager_read_unittest.cpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'test/manager_read_unittest.cpp') 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 @@ TEST(ManagerReadTest, ReadFromHandlerReturnsData) 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 data = {0x12, 0x14, 0x15, 0x16}; @@ -75,4 +75,35 @@ TEST(ManagerReadTest, ReadFromHandlerReturnsData) 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 m1 = std::make_unique(); + 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 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 result = mgr.read(sess, ofs, requested); + EXPECT_EQ(data.size(), result.size()); + EXPECT_EQ(result, data); +} + } // namespace blobs -- cgit v1.2.3