94a757
From 12fbde92a26da61eda9f2ff0ba3c316779163f10 Mon Sep 17 00:00:00 2001
94a757
From: Jean Delvare <jdelvare@suse.de>
94a757
Date: Fri, 20 Jan 2017 10:57:12 +0100
94a757
Subject: [PATCH 8/9] Only decode one DMI table
94a757
94a757
Since version 3.0.0 of the SMBIOS specification, there can be
94a757
multiple entry points in memory, pointing to one or two DMI tables.
94a757
If both a 32-bit ("_SM_") entry point and a 64-bit ("_SM3_") entry
94a757
point are present, the specification requires that the latter points
94a757
to a table which is a super-set of the table pointed to by the
94a757
former. Therefore it makes no sense to decode both.
94a757
94a757
Per specification, look for a 64-bit ("_SM3_") entry point first, and
94a757
if we can't find any, look for a 32-bit ("_SM_" or "_DMI_") entry
94a757
point.
94a757
94a757
This fixes bug #50022:
94a757
https://savannah.nongnu.org/bugs/?50022
94a757
---
94a757
 CHANGELOG   |  6 ++++++
94a757
 dmidecode.c | 19 ++++++++++++++-----
94a757
 2 files changed, 20 insertions(+), 5 deletions(-)
94a757
94a757
diff --git a/CHANGELOG b/CHANGELOG
94a757
index ac748b0..67aef99 100644
94a757
--- a/CHANGELOG
94a757
+++ b/CHANGELOG
94a757
@@ -1,3 +1,9 @@
94a757
+2017-01-20  Jean Delvare  <jdelvare@suse.de>
94a757
+
94a757
+	* dmidecode.c: Only decode one DMI table.
94a757
+	  This fixes Savannah bug #50022:
94a757
+	  https://savannah.nongnu.org/bugs/?50022
94a757
+
94a757
 2016-09-22  Jean Delvare  <jdelvare@suse.de>
94a757
94a757
	* README: Explain that we can no longer support Cygwin.
94a757
diff --git a/dmidecode.c b/dmidecode.c
94a757
index 3993592..4b46a13 100644
94a757
--- a/dmidecode.c
94a757
+++ b/dmidecode.c
94a757
@@ -4925,28 +4925,37 @@ memory_scan:
94a757
		goto exit_free;
94a757
	}
94a757
94a757
-	for (fp = 0; fp <= 0xFFF0; fp += 16)
94a757
+	/* Look for a 64-bit entry point first */
94a757
+	for (fp = 0; fp <= 0xFFE0; fp += 16)
94a757
	{
94a757
-		if (memcmp(buf + fp, "_SM3_", 5) == 0 && fp <= 0xFFE0)
94a757
+		if (memcmp(buf + fp, "_SM3_", 5) == 0)
94a757
		{
94a757
			if (smbios3_decode(buf + fp, opt.devmem, 0))
94a757
			{
94a757
				found++;
94a757
-				fp += 16;
94a757
+				goto done;
94a757
			}
94a757
		}
94a757
-		else if (memcmp(buf + fp, "_SM_", 4) == 0 && fp <= 0xFFE0)
94a757
+	}
94a757
+
94a757
+	/* If none found, look for a 32-bit entry point */
94a757
+	for (fp = 0; fp <= 0xFFF0; fp += 16)
94a757
+	{
94a757
+		if (memcmp(buf + fp, "_SM_", 4) == 0 && fp <= 0xFFE0)
94a757
		{
94a757
			if (smbios_decode(buf + fp, opt.devmem, 0))
94a757
			{
94a757
				found++;
94a757
-				fp += 16;
94a757
+				goto done;
94a757
			}
94a757
		}
94a757
		else if (memcmp(buf + fp, "_DMI_", 5) == 0)
94a757
		{
94a757
			if (legacy_decode(buf + fp, opt.devmem, 0))
94a757
+			{
94a757
				found++;
94a757
+				goto done;
94a757
+			}
94a757
		}
94a757
	}
94a757
94a757
--
94a757
2.10.2