dmidecode/dmidecode-04-use-read_file-to-read-the-dmi-table-from-sysfs.patch
Jean Delvare 925fc78f0a - dmidecode-01-add-no-sysfs-option-description-to-h-output.patch:
Add "--no-sysfs" option description to -h output.
- dmidecode-02-fix-no-smbios-nor-dmi-entry-point-found-on-smbios3.patch:
  Fix 'No SMBIOS nor DMI entry point found' on SMBIOS3.
- dmidecode-03-let-read_file-return-the-actual-data-size.patch:
  Let read_file return the actual data size.
- dmidecode-04-use-read_file-to-read-the-dmi-table-from-sysfs.patch:
  Use read_file() to read the DMI table from sysfs.
  https://savannah.nongnu.org/bugs/?46176
- dmidecode-05-use-dword-for-structure-table-maximum-size-in-smbios3.patch:
  Use DWORD for Structure table maximum size in SMBIOS3.
- dmidecode-06-hide-irrelevant-fixup-message.patch:
  Hide irrelevant fixup message.
  http://savannah.nongnu.org/support/?109024

OBS-URL: https://build.opensuse.org/package/show/Base:System/dmidecode?expand=0&rev=35
2016-05-03 14:15:10 +00:00

68 lines
2.3 KiB
Diff

From: Jean Delvare <jdelvare@suse.de>
Date: Mon, 2 Nov 2015 09:45:31 +0100
Subject: dmidecode: Use read_file() to read the DMI table from sysfs
Git-commit: 364055211b1956539c6a6268e111e244e1292c8c
References: https://savannah.nongnu.org/bugs/?46176
We shouldn't use mem_chunk() to read the DMI table from sysfs. This
will fail for SMBIOS v3 implementations which specify a maximum length
for the table rather than its exact length. The kernel will trim the
table to the actual length, so the DMI file will be shorter than the
length announced in entry point.
read_file() fits the bill in this case, as it deals with end of file
nicely.
This also helps with corrupted DMI tables, as the kernel will not
export the part of the table that it wasn't able to parse, effectively
trimming it.
This fixes bug #46176:
https://savannah.nongnu.org/bugs/?46176
Unexpected end of file error
---
dmidecode.c | 29 +++++++++++++++++++++--------
1 file changed, 21 insertions(+), 8 deletions(-)
--- dmidecode-3.0.orig/dmidecode.c 2016-05-03 16:05:09.139896776 +0200
+++ dmidecode-3.0/dmidecode.c 2016-05-03 16:05:10.336907916 +0200
@@ -4521,16 +4521,29 @@ static void dmi_table(off_t base, u32 le
printf("\n");
}
- /*
- * When we are reading the DMI table from sysfs, we want to print
- * the address of the table (done above), but the offset of the
- * data in the file is 0. When reading from /dev/mem, the offset
- * in the file is the address.
- */
if (flags & FLAG_NO_FILE_OFFSET)
- base = 0;
+ {
+ /*
+ * When reading from sysfs, the file may be shorter than
+ * announced. For SMBIOS v3 this is expcted, as we only know
+ * the maximum table size, not the actual table size. For older
+ * implementations (and for SMBIOS v3 too), this would be the
+ * result of the kernel truncating the table on parse error.
+ */
+ size_t size = len;
+ buf = read_file(&size, devmem);
+ if (!(opt.flags & FLAG_QUIET) && num && size != (size_t)len)
+ {
+ printf("Wrong DMI structures length: %u bytes "
+ "announced, only %lu bytes available.\n",
+ len, (unsigned long)size);
+ }
+ len = size;
+ }
+ else
+ buf = mem_chunk(base, len, devmem);
- if ((buf = mem_chunk(base, len, devmem)) == NULL)
+ if (buf == NULL)
{
fprintf(stderr, "Table is unreachable, sorry."
#ifndef USE_MMAP