diff options
author | Patrick Venture <venture@google.com> | 2019-02-01 14:44:15 -0800 |
---|---|---|
committer | Patrick Venture <venture@google.com> | 2019-02-01 15:13:43 -0800 |
commit | 86c87f55de9bb69f6e49c6203ffb0e12947ea7cf (patch) | |
tree | 243851da4f76e3d8f8c493de096dca8e670aad60 /test | |
parent | dc82ab15f27ca4481518e9c151c20646d4afdc8b (diff) | |
download | phosphor-ipmi-blobs-86c87f55de9bb69f6e49c6203ffb0e12947ea7cf.tar.gz phosphor-ipmi-blobs-86c87f55de9bb69f6e49c6203ffb0e12947ea7cf.zip |
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>
Diffstat (limited to 'test')
-rw-r--r-- | test/manager_read_unittest.cpp | 33 |
1 files changed, 32 insertions, 1 deletions
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<uint8_t> 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<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 |