From 47fa8d83bbeeac0ba607f62f41ab64cc179d0638 Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Sun, 4 Apr 2021 22:09:58 +0300 Subject: [PATCH] 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. --- Userland/Services/DHCPClient/main.cpp | 6 ++++-- 1 file 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 #include #include +#include #include #include #include @@ -39,8 +40,9 @@ static u8 mac_part(const Vector& 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)