diff --git a/0002-Fix-bus-errors-with-small-memory-files-Closes-58.patch b/0002-Fix-bus-errors-with-small-memory-files-Closes-58.patch new file mode 100644 index 0000000000000000000000000000000000000000..9148b2d7cb922473b257efba1dab8765f8677a69 --- /dev/null +++ b/0002-Fix-bus-errors-with-small-memory-files-Closes-58.patch @@ -0,0 +1,66 @@ +From dab5dfd01dba12fc48ff7697fc066c7856b6df2f Mon Sep 17 00:00:00 2001 +From: Mario Limonciello +Date: Mon, 16 Jul 2018 23:41:02 -0500 +Subject: [PATCH] Fix bus errors with small memory files (Closes: #58) + +--- + src/libsmbios_c/memory/memory_linux.c | 15 +++++++++++++++ + 1 file changed, 15 insertions(+) + +diff --git a/src/libsmbios_c/memory/memory_linux.c b/src/libsmbios_c/memory/memory_linux.c +index f3054bf..cc3c449 100644 +--- a/src/libsmbios_c/memory/memory_linux.c ++++ b/src/libsmbios_c/memory/memory_linux.c +@@ -28,6 +28,7 @@ + #include // memcpy + #include + #include // mmap ++#include + + #include "smbios_c/obj/memory.h" + #include "smbios_c/types.h" +@@ -46,6 +47,7 @@ struct linux_data + void *lastMapping; + off_t lastMappedOffset; + size_t mappingSize; ++ size_t fileSize; + }; + + #define READ_MMAP 0 +@@ -160,6 +162,12 @@ static int copy_mmap(const struct memory_access_obj *this, u8 *buffer, u64 offse + fnprintf("buffer(%p) offset(%lld) length(%zd) rw(%d)\n", buffer, offset, length, rw); + fnprintf("->rw: %d fd: %p\n", private_data->rw, private_data->fd); + ++ if(private_data->fileSize > 0 && length + offset > private_data->fileSize) { ++ error = _("File size is too small: File: "); ++ errno = EINVAL; ++ goto err_out; ++ } ++ + error = _("Could not (re)open file. File: "); + if( (rw && !private_data->rw) || !private_data->fd) + if (!reopen(private_data, rw)) +@@ -257,6 +265,7 @@ __hidden int init_mem_struct_filename(struct memory_access_obj *m, const char *f + int retval = 0; + const char *error; + struct linux_data *private_data; ++ struct stat st_dev; + + fnprintf("\n"); + +@@ -287,6 +296,12 @@ __hidden int init_mem_struct_filename(struct memory_access_obj *m, const char *f + error = _("File open error during memory object construction. The filename: "); + if (!reopen(private_data, false)) + goto out_fail; ++ if (fstat (fileno(private_data->fd), &st_dev) == -1) ++ goto out_fail; ++ if (S_ISCHR (st_dev.st_mode)) ++ private_data->fileSize = -1; ++ else ++ private_data->fileSize = st_dev.st_size; + closefds(private_data); + m->initialized = 1; + goto out; +-- +2.33.0 + diff --git a/libsmbios.spec b/libsmbios.spec index 7be8a0153d7956ed9fce4bae6e3b6b764d0378cd..8db5386ff4768ff683cf475dacc047bb93ae1bf2 100644 --- a/libsmbios.spec +++ b/libsmbios.spec @@ -4,13 +4,14 @@ Name: libsmbios Version: 2.4.2 -Release: 3 +Release: 4 Summary: Interface with the SMBIOS tables License: GPLv2+ or OSL 2.1 URL: https://github.com/dell/libsmbios Source0: https://github.com/dell/libsmbios/archive/v%{version}/libsmbios-%{version}.tar.gz Patch0001: 0001-libsmbios-fix-more-places-with-loop-iterators-with-b.patch +Patch0002: 0002-Fix-bus-errors-with-small-memory-files-Closes-58.patch BuildRequires: autoconf automake cppunit-devel doxygen gcc-c++ gettext gettext-devel BuildRequires: git help2man libtool libxml2-devel pkgconfig python3-devel strace valgrind @@ -170,6 +171,9 @@ rename %{pot_file}.mo %{lang_dom}.mo $(find %{buildroot}/%{_datadir} -name %{pot %{_mandir}/man?/smbios-* %changelog +* Thu Oct 12 2023 liyuanyuan - 2.4.2-4 +- Fix bus errors with small memory files + * Tue Dec 10 2019 openEuler Buildteam - 2.4.2-3 - Package init