Skip to content

Commit 50fb55b

Browse files
jdelvaregregkh
authored andcommitted
firmware: dmi_scan: Fix handling of empty DMI strings
[ Upstream commit a7770ae ] The handling of empty DMI strings looks quite broken to me: * Strings from 1 to 7 spaces are not considered empty. * True empty DMI strings (string index set to 0) are not considered empty, and result in allocating a 0-char string. * Strings with invalid index also result in allocating a 0-char string. * Strings starting with 8 spaces are all considered empty, even if non-space characters follow (sounds like a weird thing to do, but I have actually seen occurrences of this in DMI tables before.) * Strings which are considered empty are reported as 8 spaces, instead of being actually empty. Some of these issues are the result of an off-by-one error in memcmp, the rest is incorrect by design. So let's get it square: missing strings and strings made of only spaces, regardless of their length, should be treated as empty and no memory should be allocated for them. All other strings are non-empty and should be allocated. Signed-off-by: Jean Delvare <[email protected]> Fixes: 79da472 ("x86: fix DMI out of memory problems") Cc: Parag Warudkar <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Thomas Gleixner <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 589d97b commit 50fb55b

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

drivers/firmware/dmi_scan.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ EXPORT_SYMBOL_GPL(dmi_kobj);
1818
* of and an antecedent to, SMBIOS, which stands for System
1919
* Management BIOS. See further: http://www.dmtf.org/standards
2020
*/
21-
static const char dmi_empty_string[] = " ";
21+
static const char dmi_empty_string[] = "";
2222

2323
static u32 dmi_ver __initdata;
2424
static u32 dmi_len;
@@ -44,25 +44,21 @@ static int dmi_memdev_nr;
4444
static const char * __init dmi_string_nosave(const struct dmi_header *dm, u8 s)
4545
{
4646
const u8 *bp = ((u8 *) dm) + dm->length;
47+
const u8 *nsp;
4748

4849
if (s) {
49-
s--;
50-
while (s > 0 && *bp) {
50+
while (--s > 0 && *bp)
5151
bp += strlen(bp) + 1;
52-
s--;
53-
}
54-
55-
if (*bp != 0) {
56-
size_t len = strlen(bp)+1;
57-
size_t cmp_len = len > 8 ? 8 : len;
5852

59-
if (!memcmp(bp, dmi_empty_string, cmp_len))
60-
return dmi_empty_string;
53+
/* Strings containing only spaces are considered empty */
54+
nsp = bp;
55+
while (*nsp == ' ')
56+
nsp++;
57+
if (*nsp != '\0')
6158
return bp;
62-
}
6359
}
6460

65-
return "";
61+
return dmi_empty_string;
6662
}
6763

6864
static const char * __init dmi_string(const struct dmi_header *dm, u8 s)

0 commit comments

Comments
 (0)