test: serialization_test_properties: fix stale stack use
Fix use of stale stack variable. The previous code saved
the result of `path.filename().c_str()`, but since the results
of filename are a temporary it and its `c_str` only exist for
the lifetime of the statement and thus cannot be saved.
Make minor modification to the function to save the `filename()`
portion of the path rather than the filename's `c_str`, thus
extending the lifetime of the `filename()` return.
==2872441==ERROR: AddressSanitizer: stack-use-after-scope
READ of size 3 at 0x7ffcb507c3d0 thread T0
...
#3 0x556b63ed4a35 in phosphor::logging::test::TestSerialization_testProperties_Test::TestBody() ../test/serialization_test_properties.cpp:27
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I17d22741686ac964beef6cc4cb131250c5e79e9b
diff --git a/test/serialization_test_properties.cpp b/test/serialization_test_properties.cpp
index 270f8bc..6e99d5a 100644
--- a/test/serialization_test_properties.cpp
+++ b/test/serialization_test_properties.cpp
@@ -23,10 +23,10 @@
std::move(assocations), fwLevel, manager);
auto path = serialize(*input, TestSerialization::dir);
- auto idStr = path.filename().c_str();
- id = std::stol(idStr);
+ auto idStr = path.filename();
+ id = std::stol(idStr.c_str());
auto output = std::make_unique<Entry>(
- bus, std::string(OBJ_ENTRY) + '/' + idStr, id, manager);
+ bus, std::filesystem::path(OBJ_ENTRY) / idStr, id, manager);
deserialize(path, *output);
EXPECT_EQ(input->id(), output->id());