From 03588c0920c70ed424ae3ff0ea9bf846c8c5a95b Mon Sep 17 00:00:00 2001 From: zhangruifang2020 Date: Fri, 16 Jun 2023 15:16:06 +0800 Subject: [PATCH] backport patches from upstream --- ...-fix-the-buf-not-freed-in-read_field.patch | 23 +++++++++ backport-fix-warnings-in-sysfs.patch | 31 ++++++++++++ ...og-Handle-sysfs-files-without-length.patch | 50 +++++++++++++++++++ mcelog.spec | 13 ++++- 4 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 backport-fix-the-buf-not-freed-in-read_field.patch create mode 100644 backport-fix-warnings-in-sysfs.patch create mode 100644 backport-mcelog-Handle-sysfs-files-without-length.patch diff --git a/backport-fix-the-buf-not-freed-in-read_field.patch b/backport-fix-the-buf-not-freed-in-read_field.patch new file mode 100644 index 0000000..0d4fb29 --- /dev/null +++ b/backport-fix-the-buf-not-freed-in-read_field.patch @@ -0,0 +1,23 @@ +From 775527e886a94d89ac90239ef54e1ef436956e75 Mon Sep 17 00:00:00 2001 +From: huangduirong +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) + diff --git a/backport-fix-warnings-in-sysfs.patch b/backport-fix-warnings-in-sysfs.patch new file mode 100644 index 0000000..0a56c1e --- /dev/null +++ b/backport-fix-warnings-in-sysfs.patch @@ -0,0 +1,31 @@ +From 4146c9296a0cbd26f1c5e411cb44877f350053bd Mon Sep 17 00:00:00 2001 +From: Andi Kleen +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(""); + } + + diff --git a/backport-mcelog-Handle-sysfs-files-without-length.patch b/backport-mcelog-Handle-sysfs-files-without-length.patch new file mode 100644 index 0000000..b2d3444 --- /dev/null +++ b/backport-mcelog-Handle-sysfs-files-without-length.patch @@ -0,0 +1,50 @@ +From 03be76d6bd223e39e89976a9f75e1e9d19c30a18 Mon Sep 17 00:00:00 2001 +From: Andi Kleen +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 + diff --git a/mcelog.spec b/mcelog.spec index 378523d..0fe340b 100644 --- a/mcelog.spec +++ b/mcelog.spec @@ -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 - 3:168-5 +- backport patches from upstream + * Mon Nov 21 2022 shixuantong - 3:168-4 - enable check -- Gitee