Skip to content

Commit

Permalink
Merge pull request #221 from microsoft/memfixes
Browse files Browse the repository at this point in the history
Fix some memory access issues
  • Loading branch information
abeltrano authored Mar 14, 2024
2 parents d9def6b + 94a2aa9 commit 410f937
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/linux/libnl-helpers/Netlink80211Interface.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Nl80211Interface::Parse(struct nl_msg *nl80211Message) noexcept

// Parse the message.
std::array<struct nlattr *, NL80211_ATTR_MAX + 1> newInterfaceMessageAttributes{};
int ret = nla_parse(std::data(newInterfaceMessageAttributes), std::size(newInterfaceMessageAttributes), genlmsg_attrdata(genl80211MessageHeader, 0), genlmsg_attrlen(genl80211MessageHeader, 0), nullptr);
int ret = nla_parse(std::data(newInterfaceMessageAttributes), std::size(newInterfaceMessageAttributes) - 1, genlmsg_attrdata(genl80211MessageHeader, 0), genlmsg_attrlen(genl80211MessageHeader, 0), nullptr);
if (ret < 0) {
LOGE << std::format("Failed to parse netlink message attributes with error {} ({})", ret, strerror(-ret));
return std::nullopt;
Expand Down
2 changes: 1 addition & 1 deletion src/linux/libnl-helpers/Netlink80211WiphyBandFrequency.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ WiphyBandFrequency::Parse(struct nlattr *wiphyBandFrequencyNlAttribute) noexcept
{
// Parse the attribute message.
std::array<struct nlattr *, NL80211_FREQUENCY_ATTR_MAX + 1> wiphyBandFrequenciesAttributes{};
int ret = nla_parse(std::data(wiphyBandFrequenciesAttributes), std::size(wiphyBandFrequenciesAttributes), static_cast<struct nlattr *>(nla_data(wiphyBandFrequencyNlAttribute)), nla_len(wiphyBandFrequencyNlAttribute), nullptr);
int ret = nla_parse(std::data(wiphyBandFrequenciesAttributes), std::size(wiphyBandFrequenciesAttributes) - 1, static_cast<struct nlattr *>(nla_data(wiphyBandFrequencyNlAttribute)), nla_len(wiphyBandFrequencyNlAttribute), nullptr);
if (ret < 0) {
LOGE << std::format("Failed to parse wiphy band frequency attributes with error {} ({})", ret, nl_geterror(ret));
return std::nullopt;
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/linux/libnl-helpers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ add_executable(libnl-helpers-test-unit)

target_sources(libnl-helpers-test-unit
PRIVATE
Main.cxx
TestNetlink80211Interface.cxx
TestNetlink80211ProtocolState.cxx
)
Expand All @@ -14,7 +15,7 @@ target_include_directories(libnl-helpers-test-unit

target_link_libraries(libnl-helpers-test-unit
PRIVATE
Catch2::Catch2WithMain
Catch2::Catch2
libnl-helpers
magic_enum::magic_enum
)
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/linux/libnl-helpers/Main.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

#include <catch2/catch_session.hpp>
#include <plog/Appenders/ColorConsoleAppender.h>
#include <plog/Formatters/MessageOnlyFormatter.h>
#include <plog/Init.h>
#include <plog/Severity.h>

int
main(int argc, char* argv[])
{
static plog::ColorConsoleAppender<plog::MessageOnlyFormatter> colorConsoleAppender{};

plog::init(plog::debug, &colorConsoleAppender);

return Catch::Session().run(argc, argv);
}
6 changes: 4 additions & 2 deletions tests/unit/linux/wifi/core/TestAccessPointFactoryLinux.cxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#include <memory>
#include <optional>
#include <utility>

#include <catch2/catch_test_macros.hpp>
Expand Down Expand Up @@ -45,8 +46,9 @@ TEST_CASE("Destroy an AccessPointFactoryLinux instance", "[wifi][core][ap][linux

SECTION("Destroy doesn't cause a crash")
{
AccessPointFactoryLinux accessPointFactory{ std::make_unique<Test::AccessPointControllerFactoryTest>() };
REQUIRE_NOTHROW(accessPointFactory.~AccessPointFactoryLinux());
std::optional<AccessPointFactoryLinux> accessPointFactory{};
accessPointFactory.emplace(std::make_unique<Test::AccessPointControllerFactoryTest>());
REQUIRE_NOTHROW(accessPointFactory.reset());
}
}

Expand Down
5 changes: 3 additions & 2 deletions tests/unit/wifi/core/TestAccessPoint.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ TEST_CASE("Destroy an AccessPoint instance", "[wifi][core][ap]")

SECTION("Destroy doesn't cause a crash")
{
AccessPoint accessPoint{ Test::InterfaceNameDefault, std::make_unique<Test::AccessPointControllerFactoryTest>() };
REQUIRE_NOTHROW(accessPoint.~AccessPoint());
std::optional<AccessPoint> accessPoint{};
accessPoint.emplace(Test::InterfaceNameDefault, std::make_shared<Test::AccessPointControllerFactoryTest>());
REQUIRE_NOTHROW(accessPoint.reset());
}
}

Expand Down

0 comments on commit 410f937

Please sign in to comment.