Skip to content

Commit 0e9ac41

Browse files
bitWarriorbitWarrior
authored andcommitted
PR 5036 - Event vs. ASSERT if DP file is corrupted
1 parent c429a8b commit 0e9ac41

5 files changed

Lines changed: 72 additions & 3 deletions

File tree

Svc/DpCatalog/DpCatalog.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,22 @@ Fw::CmdResponse DpCatalog::loadStateFile() {
203203
// deserialization after this point should always work, since
204204
// the source buffer was specifically sized to hold the data
205205

206-
// Deserialize the file directory index
206+
// Deserialize the file directory index. If an error occurs processing the file,
207+
// generate event and return EXECUTION_ERROR.
207208
Fw::SerializeStatus status = entryBuffer.deserializeTo(this->m_stateFileData[entry].entry.dir);
208-
FW_ASSERT(Fw::FW_SERIALIZE_OK == status, status);
209+
if (status != Fw::FW_SERIALIZE_OK) {
210+
this->log_WARNING_HI_FileCorruptedDataError
211+
(this->m_stateFile, static_cast<I32>(status));
212+
stateFile.close();
213+
return Fw::CmdResponse::EXECUTION_ERROR;
214+
}
209215
status = entryBuffer.deserializeTo(this->m_stateFileData[entry].entry.record);
210-
FW_ASSERT(Fw::FW_SERIALIZE_OK == status, status);
216+
if (status != Fw::FW_SERIALIZE_OK) {
217+
this->log_WARNING_HI_FileCorruptedDataError
218+
(this->m_stateFile, static_cast<I32>(status));
219+
stateFile.close();
220+
return Fw::CmdResponse::EXECUTION_ERROR;
221+
}
211222
this->m_stateFileData[entry].used = true;
212223
this->m_stateFileData[entry].visited = false;
213224

Svc/DpCatalog/DpCatalog.fpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,15 @@ module Svc {
402402
id 46 \
403403
format "Cannot Transmit a Catalog before Building"
404404
405+
@ The file contained malformed or invalid data during deserialization
406+
event FileCorruptedDataError(
407+
file: string size FileNameStringSize @< The file
408+
stat: I32
409+
) \
410+
severity warning high \
411+
id 47 \
412+
format "DP file {} contains malformed data (status {})"
413+
405414
# ----------------------------------------------------------------------
406415
# Telemetry
407416
# ----------------------------------------------------------------------

Svc/DpCatalog/test/ut/DpCatalogTestMain.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,11 @@ TEST(OffNominal, ProcessFileInvalidDir) {
304304
tester.test_ProcessFileInvalidDir();
305305
}
306306

307+
TEST(OffNominal, MalformedFile) {
308+
Svc::DpCatalogTester tester;
309+
tester.test_MalformedFile();
310+
}
311+
307312
int main(int argc, char** argv) {
308313
::testing::InitGoogleTest(&argc, argv);
309314
return RUN_ALL_TESTS();

Svc/DpCatalog/test/ut/DpCatalogTester.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,4 +756,47 @@ void DpCatalogTester::test_ProcessFileInvalidDir() {
756756
this->component.shutdown();
757757
}
758758

759+
void DpCatalogTester::test_MalformedFile() {
760+
761+
// 1. Setup paths and corrupted data
762+
Fw::FileNameString stateFile("DpState.dat");
763+
764+
BYTE buffer[sizeof(FwIndexType) + DpRecord::SERIALIZED_SIZE];
765+
memset(buffer, 0xFF, sizeof(buffer)); // Force deserialization failure
766+
767+
// 2. Write the malformed data to disk
768+
Os::File f;
769+
ASSERT_EQ(Os::File::OP_OK, f.open(stateFile.toChar(), Os::File::OPEN_CREATE, Os::FileInterface::OVERWRITE));
770+
771+
FwSizeType writeSize = sizeof(buffer);
772+
ASSERT_EQ(Os::File::OP_OK, f.write(buffer, writeSize));
773+
f.close();
774+
775+
// 3. Configure the Component
776+
Fw::MallocAllocator mockAllocator;
777+
Fw::FileNameString dirs[DP_MAX_DIRECTORIES];
778+
this->component.configure(dirs, 0, stateFile, 0, mockAllocator);
779+
780+
// 4. Dispatch the BUILD_CATALOG command
781+
this->sendCmd_BUILD_CATALOG(0, 0);
782+
this->component.doDispatch();
783+
784+
// 5. Command should generate event instead of ASSERT
785+
ASSERT_CMD_RESPONSE_SIZE(1);
786+
//ASSERT_CMD_RESPONSE(0, DpCatalogComponentBase::OPCODE_BUILD_CATALOG, 0, Fw::CmdResponse::EXECUTION_ERROR);
787+
788+
// High-priority warning event should be caught by this test
789+
ASSERT_EVENTS_SIZE(2);
790+
ASSERT_EVENTS_FileCorruptedDataError_SIZE(1);
791+
ASSERT_EVENTS_FileCorruptedDataError(
792+
0,
793+
stateFile.toChar(),
794+
static_cast<I32>(Fw::FW_DESERIALIZE_FORMAT_ERROR)
795+
);
796+
797+
// 6. Cleanup
798+
Os::FileSystem::removeFile(stateFile.toChar());
799+
this->component.shutdown();
800+
}
801+
759802
} // namespace Svc

Svc/DpCatalog/test/ut/DpCatalogTester.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ class DpCatalogTester : public DpCatalogGTestBase {
149149
void test_PingIn();
150150
void test_BadFileDone();
151151
void test_ProcessFileInvalidDir();
152+
void test_MalformedFile();
152153
};
153154

154155
} // namespace Svc

0 commit comments

Comments
 (0)