backport Fix bus errors with small memory files
This commit is contained in:
parent
199ac75661
commit
0ecd0a7d4c
66
0002-Fix-bus-errors-with-small-memory-files-Closes-58.patch
Normal file
66
0002-Fix-bus-errors-with-small-memory-files-Closes-58.patch
Normal file
@ -0,0 +1,66 @@
|
||||
From dab5dfd01dba12fc48ff7697fc066c7856b6df2f Mon Sep 17 00:00:00 2001
|
||||
From: Mario Limonciello <mario.limonciello@dell.com>
|
||||
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 <string.h> // memcpy
|
||||
#include <errno.h>
|
||||
#include <sys/mman.h> // mmap
|
||||
+#include <sys/stat.h>
|
||||
|
||||
#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
|
||||
|
||||
@ -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 <liyuanyuan@xfusion.com> - 2.4.2-4
|
||||
- Fix bus errors with small memory files
|
||||
|
||||
* Tue Dec 10 2019 openEuler Buildteam <buildteam@openeuler.org> - 2.4.2-3
|
||||
- Package init
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user