Skip to content

Potential null pointer dereference in ManagerBase::createDvOrder() #82

@BartMassey

Description

@BartMassey

Location

File: cpp/ManagerBase.cpp:571
Function: ManagerBase::createDvOrder()

Issue

The variable depTable may be used uninitialized if no dependent relation is found.

Code

Table *depTable;
for (k = 0; k < bottomRef->getRelationCount(); ++k) {
    if (!bottomRef->getRelation(k)->isIndependentOnly()) {
        depTable = bottomRef->getRelation(k)->getTable();
        break;
    }
}
// If loop completes without finding a dependent relation, depTable is uninitialized
for (k = 0; k < depTable->getTupleCount(); ++k) {  // Line 579: potential crash

Risk

High - Will crash with null pointer dereference if no dependent relations exist in the model.

Recommended Fix

Table *depTable = nullptr;
for (k = 0; k < bottomRef->getRelationCount(); ++k) {
    if (!bottomRef->getRelation(k)->isIndependentOnly()) {
        depTable = bottomRef->getRelation(k)->getTable();
        break;
    }
}
if (depTable == nullptr) {
    fprintf(stderr, "Error: No dependent relation found\n");
    return;
}

Reference

See docs/compiler-warning-analysis.md for detailed analysis.

Priority: High
Type: Bug - Potential Crash

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions