1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:57:43 +00:00

DHCPClient: Parse MacAddress parts using StringUtils

The current parsing code assumed the ascii lowercase letters came after
the ascii numbers, which is not the case, and as such corrupted any mac
address that included hex letters (a-f). We likely did not notice this
as QEMU's emulated MAC is made up of only hex digits.
This commit is contained in:
Idan Horowitz 2021-04-04 22:09:58 +03:00 committed by Andreas Kling
parent 863bc35399
commit 47fa8d83bb

View file

@ -29,6 +29,7 @@
#include <AK/JsonArray.h>
#include <AK/JsonObject.h>
#include <AK/String.h>
#include <AK/StringUtils.h>
#include <AK/Types.h>
#include <LibCore/EventLoop.h>
#include <LibCore/File.h>
@ -39,8 +40,9 @@
static u8 mac_part(const Vector<String>& parts, size_t index)
{
auto chars = parts.at(index).characters();
return (chars[0] - '0') * 16 + (chars[1] - '0');
auto result = AK::StringUtils::convert_to_uint_from_hex(parts.at(index));
VERIFY(result.has_value());
return result.value();
}
static MACAddress mac_from_string(const String& str)