Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work/dp catalog #2713

Merged
merged 92 commits into from
Dec 11, 2024
Merged

Work/dp catalog #2713

merged 92 commits into from
Dec 11, 2024

Conversation

timcanham
Copy link
Collaborator

Related Issue(s)
Has Unit Tests (y/n)
Documentation Included (y/n)

Change Description

A description of the changes contained in the PR.

Rationale

A rationale for this change. e.g. fixes bug, or most projects need XYZ feature.

Testing/Review Recommendations

Fill in testing procedures, specific items to focus on for review, or other info to help the team verify these changes are flight-quality.

Future Work

Note any additional work that will be done relating to this issue.

Svc/DpCatalog/DpCatalog.cpp Dismissed Show dismissed Hide dismissed
Svc/DpCatalog/DpCatalog.cpp Dismissed Show dismissed Hide dismissed
Svc/DpCatalog/DpCatalog.cpp Dismissed Show dismissed Hide dismissed
Svc/DpCatalog/DpCatalog.cpp Dismissed Show dismissed Hide dismissed
Svc/DpCatalog/DpCatalog.cpp Dismissed Show dismissed Hide dismissed
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

Svc/DpCatalog/DpCatalog.cpp Dismissed Show dismissed Hide dismissed
Svc/DpCatalog/DpCatalog.cpp Dismissed Show dismissed Hide dismissed
Svc/DpCatalog/DpCatalog.cpp Fixed Show fixed Hide fixed
Svc/DpCatalog/DpCatalog.cpp Dismissed Show dismissed Hide dismissed
Svc/DpCatalog/DpCatalog.cpp Dismissed Show dismissed Hide dismissed
Svc/DpCatalog/DpCatalog.cpp Dismissed Show dismissed Hide dismissed
Svc/DpCatalog/DpCatalog.hpp Dismissed Show dismissed Hide dismissed
Svc/DpCatalog/DpCatalog.hpp Dismissed Show dismissed Hide dismissed
Svc/DpCatalog/DpCatalog.hpp Dismissed Show dismissed Hide dismissed
config/DpCfg.hpp Dismissed Show dismissed Hide dismissed
Svc/DpCatalog/DpCatalog.cpp Dismissed Show dismissed Hide dismissed
Svc/DpCatalog/DpCatalog.cpp Fixed Show fixed Hide fixed
Svc/DpCatalog/DpCatalog.cpp Fixed Show fixed Hide fixed
}

// reset the buffer for deserializing the entry
entryBuffer.setBuffLen(static_cast<Fw::Serializable::SizeType>(size));

Check warning

Code scanning / CodeQL

Unchecked return value Warning

The return value of non-void function
setBuffLen
is not checked.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should address this one.

// reset the buffer for serializing the entry
entryBuffer.resetSer();
// serialize the file directory index
entryBuffer.serialize(this->m_stateFileData[entry].entry.dir);

Check warning

Code scanning / CodeQL

Unchecked return value Warning

The return value of non-void function
serialize
is not checked.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must fix.

entryBuffer.resetSer();
// serialize the file directory index
entryBuffer.serialize(this->m_stateFileData[entry].entry.dir);
entryBuffer.serialize(this->m_stateFileData[entry].entry.record);

Check warning

Code scanning / CodeQL

Unchecked return value Warning

The return value of non-void function
serialize
is not checked.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a must fix.

Svc/DpCatalog/DpCatalog.cpp Dismissed Show dismissed Hide dismissed
Svc/DpCatalog/DpCatalog.cpp Dismissed Show dismissed Hide dismissed
Svc/DpCatalog/DpCatalog.cpp Dismissed Show dismissed Hide dismissed
Svc/DpCatalog/DpCatalog.cpp Dismissed Show dismissed Hide dismissed
Svc/DpCatalog/DpCatalog.cpp Dismissed Show dismissed Hide dismissed
@timcanham timcanham marked this pull request as ready for review December 4, 2024 23:02
Copy link
Collaborator

@LeStarch LeStarch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commenting partial review.

@@ -134,15 +135,22 @@ namespace Ref {

// if a Data product is being generated, store a record
if (this->m_dpInProgress) {
// printf("DP1: %u %u %lu %u\n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dead code

Fw::SerializeStatus stat = this->m_dpContainer.serializeRecord_DataRecord(sigInfo);
this->m_currDp++;
this->m_dpBytes += SignalInfo::SERIALIZED_SIZE;
// printf("DP2: %u %u %lu\n",this->m_dpContainer.getBuffer().getSize(),this->m_dpBytes,this->m_dpContainer.getDataSize());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dead code

@@ -41,7 +41,7 @@ namespace Ref {
test_start()
{
ASSERT_TLM_Output_SIZE(0);
sendCmd_SignalGen_Toggle(0, 0);
sendCmd_Toggle(0, 0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No UT for data product command?

@@ -17,6 +17,7 @@

// The format string for a file name
// The format arguments are base directory, container ID, time seconds, and time microseconds
constexpr const char *DP_FILENAME_FORMAT = "%s/Dp_%08" PRI_FwDpIdType "_%08" PRIu32 "_%08" PRIu32 ".fdp";
#define DP_EXT ".fdp"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why call this out when the user could edit below?

@@ -0,0 +1,12 @@

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't check in makefiles.


// buffer for reading entries

BYTE buffer[sizeof(FwIndexType)+DpRecord::SERIALIZED_SIZE];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe use sizeof(entry.dir) so it is auto-calculated?

}

// buffer for writing entries
BYTE buffer[sizeof(FwIndexType)+DpRecord::SERIALIZED_SIZE];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

FW_ASSERT(this->m_stateFileData);

// We will append state to the existing state file
// FIXME: Have to handle case where state file has partially transmitted
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixme

}

// buffer for writing entries
BYTE buffer[sizeof(FwIndexType)+DpRecord::SERIALIZED_SIZE];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this a constant, the same expression is used everywhere.

BYTE buffer[sizeof(FwIndexType)+DpRecord::SERIALIZED_SIZE];
Fw::ExternalSerializeBuffer entryBuffer(buffer, sizeof(buffer));
// reset the buffer for serializing the entry
entryBuffer.resetSer();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull this code into a helper? I see the same few lines repeated.

// fill the binary tree with DP files
response = this->fillBinaryTree();
if (response != Fw::CmdResponse::OK) {
return response;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this cause an inconsistent state? You may have failed with a partial binary tree, and an old or empty state file. This return bypasses the state file prune and write in the next (nominal) step.

@bocchino bocchino self-requested a review December 5, 2024 18:49
Copy link
Collaborator

@bocchino bocchino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Here are my comments.

Not Blocking for This PR

  1. In configure, the partitioning of memory into three pieces uses reinterpret cast on the address of an out-of-bounds array element, and it may not respect alignment requirements. This kind of code should do array access on the underlying byte buffer (so it's in bounds), it should use placement new to create the arrays, and it should respect alignment requirements.
  2. There aren't enough assertions, particularly before pointer dereference ->.

To Fix for this PR If Possible

  1. Add comments to configure to explain what is going on: (a) We are sizing a triple of arrays as an array of triples. (b) We are using array indexing to compute the address after the end of the array.
  2. For consistency, remove the explicit close operation in loadStateFile. In two other places the implicit operation is used.

@@ -102,10 +127,233 @@
this->m_initialized = true;
}

void DpCatalog::resetBinaryTree() {

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is valid.

Svc/DpCatalog/DpCatalog.cpp Dismissed Show dismissed Hide dismissed

// request memory for catalog
this->m_memSize = DP_MAX_FILES * (sizeof(DpStateEntry) + sizeof(DpSortedList));
this->m_stateFile = stateFile;

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter stateFile has not been checked.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably consider this one.

Svc/DpCatalog/DpCatalog.cpp Dismissed Show dismissed Hide dismissed
Svc/DpCatalog/DpCatalog.cpp Dismissed Show dismissed Hide dismissed
Copy link
Collaborator

@LeStarch LeStarch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing is a blocking fix, but we do need fixes eventually.


// request memory for catalog
this->m_memSize = DP_MAX_FILES * (sizeof(DpStateEntry) + sizeof(DpSortedList));
this->m_stateFile = stateFile;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably consider this one.

@@ -102,10 +127,233 @@
this->m_initialized = true;
}

void DpCatalog::resetBinaryTree() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is valid.

Svc/DpCatalog/DpCatalog.cpp Show resolved Hide resolved
}

// reset the buffer for deserializing the entry
entryBuffer.setBuffLen(static_cast<Fw::Serializable::SizeType>(size));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should address this one.

// reset the buffer for serializing the entry
entryBuffer.resetSer();
// serialize the file directory index
entryBuffer.serialize(this->m_stateFileData[entry].entry.dir);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must fix.


// insert entry into sorted list. if can't insert, quit
if (not this->insertEntry(this->m_dpList[this->m_numDpRecords])) {
if (not this->insertEntry(entry)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider fixing this.


// if the tree is empty, add the first entry
if (this->m_dpTree == nullptr) {
this->allocateNode(this->m_dpTree,entry);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must fix. Specifically since it is your return value.

DpCatalog::CheckStat DpCatalog::checkLeftRight(bool condition, DpBtreeNode* &node, const DpStateEntry& newEntry) {
if (condition) {
if (node->left == nullptr) {
if (!this->allocateNode(node->left,newEntry)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider.

}
} else {
if (node->right == nullptr) {
if (!this->allocateNode(node->right,newEntry)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider.

@LeStarch LeStarch merged commit 05b817f into nasa:devel Dec 11, 2024
32 of 35 checks passed
@LeStarch LeStarch added the Update Instructions Needed Need to add instructions in the release notes for updates. label Dec 11, 2024
@matt392code
Copy link
Contributor

Missing return value checks:
dp-catalog-checks.txt
This solution:

  1. Adds checks for buffer operations:
    -Buffer length setting
    -Serialization operations
    -Memory allocation
  2. Provides error logging:
    -Specific error codes
    -Warning messages
    -Error type enumeration
  3. Proper error handling:
    -Returns appropriate error responses
    -Maintains system state
    -Prevents undefined behavior
  4. Key improvements:
    -No more unchecked return values
    -Clear error reporting
    -Better system reliability

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Update Instructions Needed Need to add instructions in the release notes for updates.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants