From 18ca995870f03072b40eb37538bcdb16bcaadcbe Mon Sep 17 00:00:00 2001 From: Lichen Liu Date: Fri, 22 Dec 2023 15:28:28 +0800 Subject: [PATCH] dmidecode: Consistently use read_file when reading from a dump file Resovles: RHEL-19873 Signed-off-by: Lichen Liu --- ...-read_file-when-reading-from-a-dump-.patch | 64 +++++++++++++++++++ dmidecode.spec | 2 + 2 files changed, 66 insertions(+) create mode 100644 0002-Consistently-use-read_file-when-reading-from-a-dump-.patch diff --git a/0002-Consistently-use-read_file-when-reading-from-a-dump-.patch b/0002-Consistently-use-read_file-when-reading-from-a-dump-.patch new file mode 100644 index 0000000..e1f41bd --- /dev/null +++ b/0002-Consistently-use-read_file-when-reading-from-a-dump-.patch @@ -0,0 +1,64 @@ +From c76ddda0ba0aa99a55945e3290095c2ec493c892 Mon Sep 17 00:00:00 2001 +From: Jean Delvare +Date: Wed, 26 Apr 2023 15:44:27 +0200 +Subject: [PATCH] Consistently use read_file() when reading from a dump file + +Use read_file() instead of mem_chunk() to read the entry point from a +dump file. This is faster, and consistent with how we then read the +actual DMI table from that dump file. + +This made no functional difference so far, which is why it went +unnoticed for years. But now that a file type check was added to the +mem_chunk() function, we must stop using it to read from regular +files. + +This will again allow root to use the --from-dump option. + +Signed-off-by: Jean Delvare +Tested-by: Jerry Hoemann +--- + dmidecode.c | 11 +++++++++-- + 1 file changed, 9 insertions(+), 2 deletions(-) + +diff --git a/dmidecode.c b/dmidecode.c +index 54f59c1..52ddbf1 100644 +--- a/dmidecode.c ++++ b/dmidecode.c +@@ -6025,17 +6025,25 @@ int main(int argc, char * const argv[]) + pr_comment("dmidecode %s", VERSION); + + /* Read from dump if so instructed */ ++ size = 0x20; + if (opt.flags & FLAG_FROM_DUMP) + { + if (!(opt.flags & FLAG_QUIET)) + pr_info("Reading SMBIOS/DMI data from file %s.", + opt.dumpfile); +- if ((buf = mem_chunk(0, 0x20, opt.dumpfile)) == NULL) ++ if ((buf = read_file(0, &size, opt.dumpfile)) == NULL) + { + ret = 1; + goto exit_free; + } + ++ /* Truncated entry point can't be processed */ ++ if (size < 0x20) ++ { ++ ret = 1; ++ goto done; ++ } ++ + if (memcmp(buf, "_SM3_", 5) == 0) + { + if (smbios3_decode(buf, opt.dumpfile, 0)) +@@ -6059,7 +6067,6 @@ int main(int argc, char * const argv[]) + * contain one of several types of entry points, so read enough for + * the largest one, then determine what type it contains. + */ +- size = 0x20; + if (!(opt.flags & FLAG_NO_SYSFS) + && (buf = read_file(0, &size, SYS_ENTRY_FILE)) != NULL) + { +-- +2.43.0 + diff --git a/dmidecode.spec b/dmidecode.spec index cb16cc3..82680d2 100644 --- a/dmidecode.spec +++ b/dmidecode.spec @@ -10,6 +10,7 @@ BuildRequires: gcc make ExclusiveArch: %{ix86} x86_64 ia64 aarch64 Patch0: 0001-dmidecode-Add-processor-support-from-SMBIOS-3.6.0.patch +Patch1: 0002-Consistently-use-read_file-when-reading-from-a-dump-.patch %description dmidecode reports information about x86 & ia64 hardware as described in the @@ -25,6 +26,7 @@ I/O ports (e.g. serial, parallel, USB). %prep %setup -q %patch0 -p1 +%patch1 -p1 %build %make_build CFLAGS="%{optflags}" LDFLAGS="%{__global_ldflags}"