From a07e99dacf52d1618de1222f52f540b558a5944e Mon Sep 17 00:00:00 2001 From: Vitezslav Crhonek Date: Thu, 1 Aug 2024 10:23:06 +0200 Subject: [PATCH] Fix memory leaks and off-by-one error Resolves: RHEL-42557 --- ...s-2.1.1-fix-memleaks-of-by-one-error.patch | 77 +++++++++++++++++++ sysfsutils.spec | 7 +- 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 sysfsutils-2.1.1-fix-memleaks-of-by-one-error.patch diff --git a/sysfsutils-2.1.1-fix-memleaks-of-by-one-error.patch b/sysfsutils-2.1.1-fix-memleaks-of-by-one-error.patch new file mode 100644 index 0000000..7730dfa --- /dev/null +++ b/sysfsutils-2.1.1-fix-memleaks-of-by-one-error.patch @@ -0,0 +1,77 @@ +diff -up sysfsutils-2.1.1/lib/sysfs_attr.c.orig sysfsutils-2.1.1/lib/sysfs_attr.c +--- sysfsutils-2.1.1/lib/sysfs_attr.c.orig 2024-07-29 13:45:04.415961682 +0200 ++++ sysfsutils-2.1.1/lib/sysfs_attr.c 2024-07-29 13:52:54.927567946 +0200 +@@ -415,6 +415,7 @@ struct dlist *read_dir_links(const char + (SYSFS_NAME_LEN, sysfs_del_name); + if (!linklist) { + dbg_printf("Error creating list\n"); ++ closedir(dir); + return NULL; + } + } +@@ -470,6 +471,7 @@ struct sysfs_device *sysfs_read_dir_subd + dir = opendir(path); + if (!dir) { + dbg_printf("Error opening directory %s\n", path); ++ sysfs_close_device(dev); + return NULL; + } + while ((dirent = readdir(dir)) != NULL) { +@@ -524,6 +526,7 @@ struct dlist *read_dir_subdirs(const cha + (SYSFS_NAME_LEN, sysfs_del_name); + if (!dirlist) { + dbg_printf("Error creating list\n"); ++ closedir(dir); + return NULL; + } + } +@@ -573,6 +576,7 @@ struct dlist *get_attributes_list(struct + sysfs_del_attribute); + if (!alist) { + dbg_printf("Error creating list\n"); ++ closedir(dir); + return NULL; + } + } +diff -up sysfsutils-2.1.1/lib/sysfs_device.c.orig sysfsutils-2.1.1/lib/sysfs_device.c +--- sysfsutils-2.1.1/lib/sysfs_device.c.orig 2024-07-29 13:56:09.931819208 +0200 ++++ sysfsutils-2.1.1/lib/sysfs_device.c 2024-07-29 14:00:07.958159026 +0200 +@@ -247,6 +247,7 @@ struct sysfs_device *sysfs_open_device_t + if (new == NULL) { + dbg_printf("Error opening device tree at %s\n", + cur->path); ++ sysfs_close_device(devlist); + sysfs_close_device_tree(rootdev); + return NULL; + } +@@ -258,6 +259,7 @@ struct sysfs_device *sysfs_open_device_t + } + } + ++ sysfs_close_device(devlist); + return rootdev; + } + +diff -up sysfsutils-2.1.1/lib/sysfs_driver.c.orig sysfsutils-2.1.1/lib/sysfs_driver.c +--- sysfsutils-2.1.1/lib/sysfs_driver.c.orig 2021-02-19 10:49:00.000000000 +0100 ++++ sysfsutils-2.1.1/lib/sysfs_driver.c 2024-07-29 13:43:43.461857368 +0200 +@@ -255,6 +255,7 @@ struct dlist *sysfs_get_driver_devices(s + if (!drv->devices) { + dbg_printf("Error creating device list\n"); + sysfs_close_list(linklist); ++ sysfs_close_device(dev); + return NULL; + } + } +diff -up sysfsutils-2.1.1/lib/sysfs_utils.c.orig sysfsutils-2.1.1/lib/sysfs_utils.c +--- sysfsutils-2.1.1/lib/sysfs_utils.c.orig 2024-07-29 14:09:54.680028902 +0200 ++++ sysfsutils-2.1.1/lib/sysfs_utils.c 2024-07-29 14:56:44.927888046 +0200 +@@ -151,7 +151,7 @@ int sysfs_get_link(const char *path, cha + return -1; + } + +- count = readlink(path, linkpath, SYSFS_PATH_MAX); ++ count = readlink(path, linkpath, SYSFS_PATH_MAX - 1); + if (count < 0) + return -1; + else diff --git a/sysfsutils.spec b/sysfsutils.spec index d547199..e800c46 100644 --- a/sysfsutils.spec +++ b/sysfsutils.spec @@ -4,12 +4,13 @@ Name: sysfsutils Version: 2.1.1 -Release: 12%{?dist} +Release: 13%{?dist} Summary: Utilities for interfacing with sysfs URL: https://github.com/linux-ras/sysfsutils License: GPL-2.0-only Source0: https://github.com/linux-ras/sysfsutils/archive/v%{version}.tar.gz +Patch0: sysfsutils-2.1.1-fix-memleaks-of-by-one-error.patch BuildRequires: autoconf BuildRequires: automake @@ -72,6 +73,10 @@ find %{buildroot} -type f -name "*.la" -delete %changelog +* Thu Aug 01 2024 Vitezslav Crhonek - 2.1.1-13 +- Fix memory leaks and off-by-one error + Resolves: RHEL-42557 + * Wed Jul 24 2024 Vitezslav Crhonek - 2.1.1-12 - Rebuild