Skip to content

Commit

Permalink
Extra arg checking.
Browse files Browse the repository at this point in the history
  • Loading branch information
abeltrano committed Jan 16, 2024
1 parent 8f3a88d commit 173115c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
20 changes: 11 additions & 9 deletions src/linux/libnl-helpers/Netlink80211Wiphy.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ HandleNl80211GetWiphyResponse(struct nl_msg *nl80211Message, void *context) noex
if (!nl80211WiphyResult.has_value()) {
LOGE << "Failed to parse nl80211 wiphy message";
return NL_SKIP;
} else {
LOGD << std::format("Successfully parsed an nl80211 wiphy:\n{}", nl80211WiphyResult->ToString());
}

LOGD << std::format("Successfully parsed an nl80211 wiphy:\n{}", nl80211WiphyResult->ToString());

return NL_OK;
}
} // namespace detail
Expand Down Expand Up @@ -135,6 +135,11 @@ Nl80211Wiphy::Parse(struct nl_msg *nl80211Message) noexcept
}

// Process top-level identifiers.
if (wiphyAttributes[NL80211_ATTR_WIPHY] == nullptr || wiphyAttributes[NL80211_ATTR_WIPHY_NAME] == nullptr) {
LOGE << "Received nl80211 message with missing wiphy index or name";
return std::nullopt;
}

auto wiphyIndex = static_cast<uint32_t>(nla_get_u32(wiphyAttributes[NL80211_ATTR_WIPHY]));
auto wiphyName = static_cast<const char *>(nla_data(wiphyAttributes[NL80211_ATTR_WIPHY_NAME]));

Expand All @@ -157,13 +162,12 @@ Nl80211Wiphy::Parse(struct nl_msg *nl80211Message) noexcept
wiphyBandMap.emplace(nl80211BandType, std::move(nl80211Band.value()));
}
}
} else {
LOGW << "No wiphy bands";
}

// Process cipher suites.
auto wiphyNumCipherSuites = static_cast<std::size_t>(nla_len(wiphyAttributes[NL80211_ATTR_CIPHER_SUITES])) / sizeof(uint32_t);
auto *wiphyCipherSuites = static_cast<uint32_t *>(nla_data(wiphyAttributes[NL80211_ATTR_CIPHER_SUITES]));
uint32_t *wiphyCipherSuites;
auto wiphyNumCipherSuites = static_cast<std::size_t>(nla_len(wiphyAttributes[NL80211_ATTR_CIPHER_SUITES])) / sizeof(*wiphyCipherSuites);
wiphyCipherSuites = static_cast<uint32_t *>(nla_data(wiphyAttributes[NL80211_ATTR_CIPHER_SUITES]));
std::vector<uint32_t> cipherSuites(wiphyCipherSuites, wiphyCipherSuites + wiphyNumCipherSuites);

// Process supported interface types.
Expand All @@ -176,8 +180,6 @@ Nl80211Wiphy::Parse(struct nl_msg *nl80211Message) noexcept
auto interfaceType = static_cast<nl80211_iftype>(supportedInterfaceType->nla_type);
supportedInterfaceTypes.emplace_back(interfaceType);
}
} else {
LOGW << "No supported interface types";
}

// Process roaming support.
Expand All @@ -192,7 +194,7 @@ Nl80211Wiphy::ToString() const
{
std::ostringstream ss;

ss << std::format("[{}] {}\n", Index, Name);
ss << std::format("Wiphy {} [{}]\n", Name, Index);
ss << std::format(" Supports roaming: {}\n", SupportsRoaming);

ss << " Cipher Suites:\n ";
Expand Down
2 changes: 0 additions & 2 deletions src/linux/libnl-helpers/Netlink80211WiphyBand.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ Nl80211WiphyBand::Parse(struct nlattr *wiphyBand) noexcept
frequencies.emplace_back(std::move(frequency.value()));
}
}
} else {
LOGW << "No frequencies for band";
}

std::vector<uint32_t> bitRates{};
Expand Down
5 changes: 2 additions & 3 deletions src/linux/libnl-helpers/Netlink80211WiphyBandFrequency.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ WiphyBandFrequency::Parse(struct nlattr *wiphyBandFrequencyNlAttribute) noexcept
}

if (wiphyBandFrequenciesAttributes[NL80211_FREQUENCY_ATTR_FREQ] == nullptr) {
LOGW << "Received null wiphy band frequency";
return std::nullopt;
}

auto isDisabled = wiphyBandFrequenciesAttributes[NL80211_FREQUENCY_ATTR_DISABLED] != nullptr;
auto frequency = static_cast<uint32_t>(nla_get_u32(wiphyBandFrequenciesAttributes[NL80211_FREQUENCY_ATTR_FREQ]));
const auto isDisabled = wiphyBandFrequenciesAttributes[NL80211_FREQUENCY_ATTR_DISABLED] != nullptr;
const auto frequency = static_cast<uint32_t>(nla_get_u32(wiphyBandFrequenciesAttributes[NL80211_FREQUENCY_ATTR_FREQ]));
std::optional<uint32_t> frequencyOffset{};
if (wiphyBandFrequenciesAttributes[NL80211_FREQUENCY_ATTR_OFFSET] != nullptr) {
frequencyOffset = static_cast<uint32_t>(nla_get_u32(wiphyBandFrequenciesAttributes[NL80211_FREQUENCY_ATTR_OFFSET]));
Expand Down

0 comments on commit 173115c

Please sign in to comment.