summaryrefslogtreecommitdiff
path: root/dmioem.c
diff options
context:
space:
mode:
authorJean Delvare <jdelvare@suse.de>2020-12-10 11:21:41 +0100
committerJean Delvare <jdelvare@suse.de>2020-12-10 11:21:41 +0100
commit617957c22f74ab2dadc16663b6c694e594ba921f (patch)
tree0fa6a31c236aa5f47113c367dd67b6b46f635ae6 /dmioem.c
parentac6a64496fc99a5cc05ebe4dd7d1b88f60041009 (diff)
downloaddmidecode-git-617957c22f74ab2dadc16663b6c694e594ba921f.tar.gz
dmioem: Fix vendor string comparison
The vendor string comparison code made an incorrect assumption about the length of the vendor string found in the DMI table. We would hit a false positive if that string was shorter than, and an exact prefix of, the vendor string we were comparing with. Explicitly check for length equality before comparing the strings. Also rewrite the whole thing as an iteration over a table, instead of open-coding it. This will make it easier to add support for more vendors in the future. Signed-off-by: Jean Delvare <jdelvare@suse.de>
Diffstat (limited to 'dmioem.c')
-rw-r--r--dmioem.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/dmioem.c b/dmioem.c
index bf8def1..f4be628 100644
--- a/dmioem.c
+++ b/dmioem.c
@@ -52,7 +52,17 @@ static const char *dmi_product = NULL;
*/
void dmi_set_vendor(const char *s, const char *p)
{
- int len;
+ const struct { const char *str; enum DMI_VENDORS id; } vendor[] = {
+ { "Acer", VENDOR_ACER },
+ { "HP", VENDOR_HP },
+ { "Hewlett-Packard", VENDOR_HP },
+ { "HPE", VENDOR_HPE },
+ { "Hewlett Packard Enterprise", VENDOR_HPE },
+ { "IBM", VENDOR_IBM },
+ { "LENOVO", VENDOR_LENOVO },
+ };
+ unsigned int i;
+ size_t len;
/*
* Often DMI strings have trailing spaces. Ignore these
@@ -62,16 +72,15 @@ void dmi_set_vendor(const char *s, const char *p)
while (len && s[len - 1] == ' ')
len--;
- if (strncmp(s, "Acer", len) == 0)
- dmi_vendor = VENDOR_ACER;
- else if (strncmp(s, "HP", len) == 0 || strncmp(s, "Hewlett-Packard", len) == 0)
- dmi_vendor = VENDOR_HP;
- else if (strncmp(s, "HPE", len) == 0 || strncmp(s, "Hewlett Packard Enterprise", len) == 0)
- dmi_vendor = VENDOR_HPE;
- else if (strncmp(s, "IBM", len) == 0)
- dmi_vendor = VENDOR_IBM;
- else if (strncmp(s, "LENOVO", len) == 0)
- dmi_vendor = VENDOR_LENOVO;
+ for (i = 0; i < ARRAY_SIZE(vendor); i++)
+ {
+ if (strlen(vendor[i].str) == len &&
+ strncmp(s, vendor[i].str, len) == 0)
+ {
+ dmi_vendor = vendor[i].id;
+ break;
+ }
+ }
dmi_product = p;
}