diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2021-04-04 22:09:58 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-04-04 21:22:25 +0200 |
commit | 47fa8d83bbeeac0ba607f62f41ab64cc179d0638 (patch) | |
tree | 2a705d43e6c9d04b7f8bb99569cd80f176fe4ad2 /Userland/Services/DHCPClient | |
parent | 863bc35399a78cde360414b057e06f303be87573 (diff) | |
download | serenity-47fa8d83bbeeac0ba607f62f41ab64cc179d0638.zip |
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.
Diffstat (limited to 'Userland/Services/DHCPClient')
-rw-r--r-- | Userland/Services/DHCPClient/main.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/Userland/Services/DHCPClient/main.cpp b/Userland/Services/DHCPClient/main.cpp index 8def7ec954..a70a9fc045 100644 --- a/Userland/Services/DHCPClient/main.cpp +++ b/Userland/Services/DHCPClient/main.cpp @@ -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) |