From: Daniel Wagner Date: Thu, 30 Mar 2023 14:14:19 +0000 (+0200) Subject: fabrics: Filter out invalid UUIDs from DMI X-Git-Tag: v1.4~2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=fc1127bb62d34ad584bb070feff6509e528f7c38;p=users%2Fsagi%2Flibnvme.git fabrics: Filter out invalid UUIDs from DMI Qemu might not initialize the system DMI correctly and nvme-cli would generate an invalid hostid. Signed-off-by: Daniel Wagner --- diff --git a/src/nvme/fabrics.c b/src/nvme/fabrics.c index d6ae3351..3c32e271 100644 --- a/src/nvme/fabrics.c +++ b/src/nvme/fabrics.c @@ -1018,6 +1018,25 @@ static int uuid_from_device_tree(char *system_uuid) */ #define DMI_SYSTEM_INFORMATION 1 +static bool is_dmi_uuid_valid(const char *buf, size_t len) +{ + int i; + + /* UUID bytes are from byte 8 to 23 */ + if (len < 24) + return false; + + /* Test it's a invalid UUID with all zeros */ + for (i = 8; i < 24; i++) { + if (buf[i]) + break; + } + if (i == 24) + return false; + + return true; +} + static int uuid_from_dmi_entries(char *system_uuid) { int f; @@ -1053,8 +1072,10 @@ static int uuid_from_dmi_entries(char *system_uuid) continue; len = read(f, buf, 512); close(f); - if (len <= 0) + + if (!is_dmi_uuid_valid(buf, len)) continue; + /* Sigh. https://en.wikipedia.org/wiki/Overengineering */ /* DMTF SMBIOS 3.0 Section 7.2.1 System UUID */ sprintf(system_uuid,