Skip to content

Commit

Permalink
Ensure we don't get an NPE if the Stack is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
peternewman committed Apr 21, 2024
1 parent bc81275 commit 54d2743
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libs/acn/LLRPProbeReplyPDU.cpp
Expand Up @@ -57,6 +57,11 @@ void LLRPProbeReplyPDU::PrependPDU(ola::io::IOStack *stack,
const UID &target_uid,
const MACAddress &hardware_address,
const LLRPComponentType type) {
if (!stack) {
OLA_WARN << "LLRPProbeReplyPDU::PrependPDU: missing stack";
return;
}

llrp_probe_reply_pdu_data data;
target_uid.Pack(data.target_uid, sizeof(data.target_uid));
hardware_address.Pack(data.hardware_address, sizeof(data.hardware_address));
Expand Down
8 changes: 8 additions & 0 deletions libs/acn/LLRPProbeReplyPDUTest.cpp
Expand Up @@ -176,6 +176,14 @@ void LLRPProbeReplyPDUTest::testPrepend() {
0xff
};
OLA_ASSERT_DATA_EQUALS(expected_data, sizeof(expected_data), buffer, length);

// test null stack
LLRPProbeReplyPDU::PrependPDU(
NULL,
target_uid,
hardware_address,
LLRPProbeReplyPDU::LLRP_COMPONENT_TYPE_NON_RDMNET);

delete[] buffer;
}
} // namespace acn
Expand Down
5 changes: 5 additions & 0 deletions libs/acn/LLRPProbeRequestPDU.cpp
Expand Up @@ -86,6 +86,11 @@ void LLRPProbeRequestPDU::PrependPDU(ola::io::IOStack *stack,
bool client_tcp_connection_inactive,
bool brokers_only,
const ola::rdm::UIDSet &known_uids) {
if (!stack) {
OLA_WARN << "LLRPProbeRequestPDU::PrependPDU: missing stack";
return;
}

llrp_probe_request_pdu_data data;
lower_uid.Pack(data.lower_uid, sizeof(data.lower_uid));
upper_uid.Pack(data.upper_uid, sizeof(data.upper_uid));
Expand Down
9 changes: 9 additions & 0 deletions libs/acn/LLRPProbeRequestPDUTest.cpp
Expand Up @@ -191,6 +191,15 @@ void LLRPProbeRequestPDUTest::testPrepend() {
0x56, 0x78, 0, 0, 0, 2,
};
OLA_ASSERT_DATA_EQUALS(expected_data, sizeof(expected_data), buffer, length);

// test null stack
LLRPProbeRequestPDU::PrependPDU(NULL,
UID(0x0000, 0x00000000),
UID(0xffff, 0xffffffff),
false,
false,
known_uids);

delete[] buffer;
}
} // namespace acn
Expand Down

0 comments on commit 54d2743

Please sign in to comment.