Skip to content

Commit 765fe74

Browse files
committed
Tighten signaling error conditions.
1 parent aefb60f commit 765fe74

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

src/common/wifi/core/include/microsoft/net/wifi/Ieee80211Authentication.hxx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ using Ieee80211RsnaPskVariant = std::variant<Ieee80211RsnaPskPassphrase, Ieee802
2626
* @brief Encoding of a pre-shared key.
2727
*/
2828
enum class Ieee80211RsnaPskEncoding {
29+
Invalid,
2930
Passphrase,
3031
Value,
3132
};
@@ -50,9 +51,13 @@ struct Ieee80211RsnaPsk :
5051
constexpr Ieee80211RsnaPskEncoding
5152
Encoding() const noexcept
5253
{
54+
// clang-format off
5355
return std::holds_alternative<Ieee80211RsnaPskPassphrase>(*this)
5456
? Ieee80211RsnaPskEncoding::Passphrase
55-
: Ieee80211RsnaPskEncoding::Value;
57+
: std::holds_alternative<Ieee80211RsnaPskValue>(*this)
58+
? Ieee80211RsnaPskEncoding::Value
59+
: Ieee80211RsnaPskEncoding::Invalid;
60+
// clang-format on
5661
}
5762

5863
/**

src/common/wifi/dot11/adapter/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ target_link_libraries(wifi-core-adapter-dot11
2121
wifi-core
2222
PRIVATE
2323
notstd
24+
strings
2425
)
2526

2627
install(

src/common/wifi/dot11/adapter/Ieee80211Dot11Adapters.cxx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <microsoft/net/wifi/Ieee80211.hxx>
1414
#include <microsoft/net/wifi/Ieee80211AccessPointCapabilities.hxx>
1515
#include <microsoft/net/wifi/Ieee80211Dot11Adapters.hxx>
16+
#include <strings/StringParsing.hxx>
1617

1718
namespace Microsoft::Net::Wifi
1819
{
@@ -661,19 +662,15 @@ FromDot11RsnaPsk(const Dot11RsnaPsk& dot11RsnaPsk) noexcept
661662

662663
if (pskValue.has_hex()) {
663664
const auto& pskHex = pskValue.hex();
664-
// Ensure the hex string is at least twice the length of the value array (2 hex characters per byte).
665-
if (std::size(pskHex) >= std::size(ieee80211RsnaPsk.Value()) * 2) {
666-
std::string_view pskHexView{ pskHex };
667-
std::vector<uint8_t> pskValueRawV(std::size(pskValueRaw));
668-
for (std::size_t i = 0; i < std::size(pskValueRaw); i++) {
669-
const auto byteAsHex = pskHexView.substr(i * 2, 2); // 2 hex chars
670-
std::from_chars(std::data(byteAsHex), std::data(byteAsHex) + std::size(byteAsHex), pskValueRaw[i], 16);
671-
}
665+
if (!Strings::ParseHexString(pskHex, pskValueRaw)) {
666+
ieee80211RsnaPsk = {};
672667
}
673668
} else if (pskValue.has_raw()) {
674669
const auto& pskRaw = pskValue.raw();
675670
if (std::size(pskRaw) >= std::size(pskValueRaw)) {
676671
std::ranges::copy_n(std::cbegin(pskRaw), static_cast<long>(std::size(pskValueRaw)), std::begin(pskValueRaw));
672+
} else {
673+
ieee80211RsnaPsk = {};
677674
}
678675
} else {
679676
ieee80211RsnaPsk = {};

0 commit comments

Comments
 (0)