diff options
author | Liav A <liavalb@gmail.com> | 2022-06-10 23:02:35 +0300 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-06-10 22:32:54 +0100 |
commit | 1a641f9af7fc66df1a725fc76acba08cbbe28070 (patch) | |
tree | e7cb7988ca992c33c78b9137e3932d83ea849285 | |
parent | 20c9e4c05c428f4a6ae6d955abb0429475446865 (diff) | |
download | serenity-1a641f9af7fc66df1a725fc76acba08cbbe28070.zip |
LibEDID: Return "Unknown" string if failed to determine the manufacturer
Before of this patch, It happened that the return string could be "@@@",
as a result of doing mathematical addition of ASCII '@' with bits when
decoding the packed manufacturer ID bytes from the EDID.
To avoid this, consider m_legacy_manufacturer_id to be invalid until we
successfully decode the packed bytes.
-rw-r--r-- | Userland/Libraries/LibEDID/EDID.cpp | 5 | ||||
-rw-r--r-- | Userland/Libraries/LibEDID/EDID.h | 1 |
2 files changed, 6 insertions, 0 deletions
diff --git a/Userland/Libraries/LibEDID/EDID.cpp b/Userland/Libraries/LibEDID/EDID.cpp index c343146eb9..865d683c26 100644 --- a/Userland/Libraries/LibEDID/EDID.cpp +++ b/Userland/Libraries/LibEDID/EDID.cpp @@ -332,10 +332,13 @@ ErrorOr<void> Parser::parse() } u16 packed_id = read_be(&raw_edid().vendor.manufacturer_id); + if (packed_id == 0x0) + return {}; m_legacy_manufacturer_id[0] = (char)((u16)'A' + ((packed_id >> 10) & 0x1f) - 1); m_legacy_manufacturer_id[1] = (char)((u16)'A' + ((packed_id >> 5) & 0x1f) - 1); m_legacy_manufacturer_id[2] = (char)((u16)'A' + (packed_id & 0x1f) - 1); m_legacy_manufacturer_id[3] = '\0'; + m_legacy_manufacturer_id_valid = true; return {}; } @@ -420,6 +423,8 @@ StringView Parser::legacy_manufacturer_id() const #ifndef KERNEL String Parser::manufacturer_name() const { + if (!m_legacy_manufacturer_id_valid) + return "Unknown"; auto manufacturer_id = legacy_manufacturer_id(); # ifdef ENABLE_PNP_IDS_DATA if (auto pnp_id_data = PnpIDs::find_by_manufacturer_id(manufacturer_id); pnp_id_data.has_value()) diff --git a/Userland/Libraries/LibEDID/EDID.h b/Userland/Libraries/LibEDID/EDID.h index 63a7f1a616..6ccfc23aa0 100644 --- a/Userland/Libraries/LibEDID/EDID.h +++ b/Userland/Libraries/LibEDID/EDID.h @@ -457,6 +457,7 @@ private: String m_version; #endif char m_legacy_manufacturer_id[4] {}; + bool m_legacy_manufacturer_id_valid { false }; }; } |