backport patches from upstream

This commit is contained in:
zhangruifang2020 2023-06-16 15:53:40 +08:00
parent 4b33a43f12
commit 95589b051d
4 changed files with 116 additions and 1 deletions

View File

@ -0,0 +1,23 @@
From 775527e886a94d89ac90239ef54e1ef436956e75 Mon Sep 17 00:00:00 2001
From: huangduirong <huangduirong@huawei.com>
Date: Sat, 9 Oct 2021 16:50:08 +0800
Subject: [PATCH] fix the buf not freed in read_field
---
sysfs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sysfs.c b/sysfs.c
index 7e7166e..018f294 100644
--- a/sysfs.c
+++ b/sysfs.c
@@ -39,7 +39,7 @@ char *read_field(char *base, char *name)
fd = open(fn, O_RDONLY);
free(fn);
if (fd < 0)
- goto bad;
+ goto bad_buf;
n = read(fd, buf, 4096);
close(fd);
if (n < 0)

View File

@ -0,0 +1,31 @@
From 4146c9296a0cbd26f1c5e411cb44877f350053bd Mon Sep 17 00:00:00 2001
From: Andi Kleen <ak@linux.intel.com>
Date: Thu, 9 Dec 2021 17:12:29 -0800
Subject: [PATCH] Fix warnings in sysfs.c
---
sysfs.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/sysfs.c b/sysfs.c
index 018f294..cd0f7c7 100644
--- a/sysfs.c
+++ b/sysfs.c
@@ -31,7 +31,6 @@ char *read_field(char *base, char *name)
{
char *fn, *val;
int n, fd;
- struct stat st;
char *s;
char *buf = xalloc(4096);
@@ -55,7 +54,6 @@ char *read_field(char *base, char *name)
bad_buf:
free(buf);
-bad:
SYSERRprintf("Cannot read sysfs field %s/%s", base, name);
return xstrdup("");
}

View File

@ -0,0 +1,50 @@
From 03be76d6bd223e39e89976a9f75e1e9d19c30a18 Mon Sep 17 00:00:00 2001
From: Andi Kleen <andi@firstfloor.org>
Date: Sat, 2 Oct 2021 16:45:20 -0700
Subject: [PATCH] mcelog: Handle sysfs files without length
---
sysfs.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/sysfs.c b/sysfs.c
index bc61b4a..7e7166e 100644
--- a/sysfs.c
+++ b/sysfs.c
@@ -33,29 +33,25 @@ char *read_field(char *base, char *name)
int n, fd;
struct stat st;
char *s;
- char *buf = NULL;
+ char *buf = xalloc(4096);
xasprintf(&fn, "%s/%s", base, name);
fd = open(fn, O_RDONLY);
free(fn);
if (fd < 0)
goto bad;
- if (fstat(fd, &st) < 0) {
- close(fd);
- goto bad;
- }
- buf = xalloc(st.st_size);
- n = read(fd, buf, st.st_size);
+ n = read(fd, buf, 4096);
close(fd);
if (n < 0)
goto bad_buf;
val = xalloc(n + 1);
memcpy(val, buf, n);
+ val[n] = 0;
free(buf);
s = memchr(val, '\n', n);
if (s)
*s = 0;
- return val;
+ return val;
bad_buf:
free(buf);
--
2.25.1

View File

@ -5,7 +5,7 @@
Name: mcelog
Version: 168
Release: 4
Release: 5
Epoch: 3
Summary: Linux kernel machine check handling middleware
License: GPLv2
@ -14,6 +14,11 @@ Source0: https://github.com/andikleen/%{name}/archive/v%{last_tar_version}.tar.g
Source1: mce-inject-%{mce_inject_ver}.tar.bz2
Source2: aer-inject-%{aer_inject_ver}.tar.bz2
Source3: mcelog.conf
Patch0:backport-mcelog-Handle-sysfs-files-without-length.patch
Patch1:backport-fix-the-buf-not-freed-in-read_field.patch
Patch2:backport-fix-warnings-in-sysfs.patch
ExclusiveArch: i686 x86_64
BuildRequires: bison flex systemd gcc psmisc
Requires(post): systemd
@ -32,6 +37,9 @@ driver error recovery handler and PCIE AER core handler.
%prep
%setup -q -n %{name}-%{last_tar_version} -a 1 -a 2
%patch0 -p1
%patch1 -p1
%patch2 -p1
%build
make CFLAGS="$RPM_OPT_FLAGS -Wl,-z,relro,-z,now -fpie" LDFLAGS="-Wl,-z,relro,-z,now -fpie -pie"
@ -80,6 +88,9 @@ rm -rf $RPM_BUILD_ROOT
%attr(0644,root,root) %{_mandir}/*/*
%changelog
* Fri Jun 16 2023 zhangruifang2020 <zhangruifang1@h-partners.com> - 3:168-5
- backport patches from upstream
* Tue Nov 22 2022 shixuantong <shixuantong1@huawei.com> - 3:168-4
- enable check