Compare commits

...

10 Commits

Author SHA1 Message Date
openeuler-ci-bot
985230adae
!33 [sync] PR-32: backport community patches to fix mem leak in sysfs_attr.c, sysfs_device.c, and sysfs_driver.c
From: @openeuler-sync-bot 
Reviewed-by: @swf504 
Signed-off-by: @swf504
2023-05-08 08:10:16 +00:00
Jiangtian Feng
e63dcab109 backport community patches to fix mem leak in sysfs_attr.c, sysfs_device.c, and sysfs_driver.c
Signed-off-by: Jiangtian Feng <fengjiangtian@huawei.com>
(cherry picked from commit f77d45dea5cd3e0494add9c6176aa41713b23b9b)
2023-05-08 15:07:20 +08:00
openeuler-ci-bot
d7a0815465
!21 correcting errors in 0009-path_is_file-should-call-stat-not-lstat.patch
From: @markeryang 
Reviewed-by: @liuzhiqiang26 
Signed-off-by: @liuzhiqiang26
2022-03-30 09:30:17 +00:00
markeryang
efa87e05c9 correcting errors in 0009-path_is_file-should-call-stat-not-lstat.patch 2022-03-30 17:10:45 +08:00
openeuler-ci-bot
7fe59f3530 !16 [sync] PR-15: 将各个具有相同version的分支的release号拉到一致,确保没有信息在各个分支上丢失
From: @openeuler-sync-bot
Reviewed-by: @liuzhiqiang26
Signed-off-by: @liuzhiqiang26
2021-09-28 06:04:26 +00:00
chenyanpanHW
3dbcc7d283 delete -S git from %autosetup, and delete BuildRequires git
(cherry picked from commit b7cf0ff693cc5b09ba0ab3d4ab4617a872f06022)
2021-09-28 11:13:25 +08:00
lixiaokeng
ff37c4949a add make check
(cherry picked from commit cb99d1f844867df3a54f65387e8bfbdb5ecdbb72)
2021-09-28 11:13:25 +08:00
Zhiqiang Liu
affb9f34c2 sysfsutils: backport upstream bugfix patches
sysfsutils: backport upstream bugfix patches

Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
(cherry picked from commit f04b8c6274b7f28ac28031237a113430acf1863e)
2021-09-28 11:13:25 +08:00
lfl
efc368d525 update sysfsutils.spec.
(cherry picked from commit b723ea50b278bb90b76511ceb5f2336683485f4b)
2021-09-28 11:13:25 +08:00
volcanodragon
da3b2554bd rename patch
(cherry picked from commit 8dd0421473738cc5df2a3e99b4fdf20c49fe2515)
2021-09-28 11:13:25 +08:00
11 changed files with 350 additions and 18 deletions

View File

@ -0,0 +1,60 @@
From 744befa9faa3446ff6bf0627cadb6a3addae1dd1 Mon Sep 17 00:00:00 2001
From: Lee Duncan <lduncan@suse.com>
Date: Fri, 3 Jul 2020 11:14:20 -0700
Subject: [PATCH 1/9] Fix issue with sysfs name comparisons.
It turns out that cdev_name_equal() is used
by dlist_find_custom() to compare sysfs
entry names to ones already seen. But it was
comparing using the length of the shortest string
as a maximum, so when it compared, for example,
"eth1" and "eth10", it thought they were the same.
So now just return failure if the strings
aren't the same length, else go ahead and
compare them.
Signed-off-by: Lee Duncan <lduncan@suse.com>
---
lib/sysfs_class.c | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/lib/sysfs_class.c b/lib/sysfs_class.c
index 4fe0b82..c696ff0 100644
--- a/lib/sysfs_class.c
+++ b/lib/sysfs_class.c
@@ -60,13 +60,30 @@ void sysfs_close_class(struct sysfs_class *cls)
}
}
+/*
+ * pass this function to dlist_find_custom()
+ * so it can compare device names
+ *
+ * return 1 if pathnames are equal, else 0
+ */
static int cdev_name_equal(void *a, void *b)
{
+ size_t length_a, length_b;
+ char *str_a, *str_b;
+
if (!a || !b)
return 0;
- if (strncmp((char *)a, ((struct sysfs_class_device *)b)->name,
- strlen((char *)a)) == 0)
+ str_a = (char *)a;
+ str_b = ((struct sysfs_class_device *)b)->name;
+
+ length_a = strnlen(str_a, SYSFS_NAME_LEN+1);
+ length_b = strnlen(str_b, SYSFS_NAME_LEN+1);
+
+ if (length_a != length_b)
+ return 0;
+
+ if (strncmp(str_a, str_b, SYSFS_NAME_LEN+1) == 0)
return 1;
return 0;
--
1.8.3.1

View File

@ -1,12 +0,0 @@
diff -puN lib/sysfs_class.c~sysfsutils_class_dup lib/sysfs_class.c
--- sysfsutils-2.1.0/lib/sysfs_class.c~sysfsutils_class_dup 2006-09-07 17:01:26.000000000 -0500
+++ sysfsutils-2.1.0-bjking1/lib/sysfs_class.c 2006-09-07 17:01:26.000000000 -0500
@@ -66,7 +66,7 @@ static int cdev_name_equal(void *a, void
return 0;
if (strncmp((char *)a, ((struct sysfs_class_device *)b)->name,
- strlen((char *)a)) == 0)
+ SYSFS_NAME_LEN) == 0)
return 1;
return 0;

View File

@ -0,0 +1,28 @@
From 8c4c03717d6b9690d5adc70968a14819dc9a36e9 Mon Sep 17 00:00:00 2001
From: Lee Duncan <lduncan@suse.com>
Date: Wed, 26 Feb 2020 09:16:32 -0800
Subject: [PATCH 6/9] fix of FUNC_TABLE_SIZE mentioned in prev commit
fix of FUNC_TABLE_SIZE mentioned in prev commit.
Signed-off-by: Lee Duncan <lduncan@suse.com>
---
test/test-defs.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/test-defs.h b/test/test-defs.h
index b22909a..28af1a5 100644
--- a/test/test-defs.h
+++ b/test/test-defs.h
@@ -40,7 +40,7 @@
#define val_drv1_attr_name "dummy2"
#define inval_name "invalid_name"
#define inval_path "/sys/invalid/path"
-#define FUNC_TABLE_SIZE (sizeof(func_table)/sizeof(int))
+#define FUNC_TABLE_SIZE (sizeof(func_table) / sizeof(void *))
FILE *my_stdout;
--
1.8.3.1

View File

@ -0,0 +1,43 @@
From 049f2664ce29bd11c07894bbdef51b8d610b1d12 Mon Sep 17 00:00:00 2001
From: Lee Duncan <lduncan@suse.com>
Date: Wed, 24 Jun 2020 11:07:53 -0700
Subject: [PATCH 7/9] Fix compiler complain about multiple defs of my_stdout.
A simple fix: define it in one place, refer to it
elsewhere.
Signed-off-by: Lee Duncan <lduncan@suse.com>
---
test/test-defs.h | 2 +-
test/test.c | 2 ++
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/test/test-defs.h b/test/test-defs.h
index 28af1a5..3378373 100644
--- a/test/test-defs.h
+++ b/test/test-defs.h
@@ -42,7 +42,7 @@
#define inval_path "/sys/invalid/path"
#define FUNC_TABLE_SIZE (sizeof(func_table) / sizeof(void *))
-FILE *my_stdout;
+extern FILE *my_stdout;
#define dbg_print(format, arg...) fprintf(my_stdout, format, ## arg)
diff --git a/test/test.c b/test/test.c
index 2e8f201..f63e346 100644
--- a/test/test.c
+++ b/test/test.c
@@ -27,6 +27,8 @@
#include "test-defs.h"
#include <errno.h>
+FILE *my_stdout;
+
/*************************************************/
char *function_name[] = {
"sysfs_get_mnt_path",
--
1.8.3.1

View File

@ -0,0 +1,29 @@
From e92be090a8a82c679a65bc0c885e259c3c64cc51 Mon Sep 17 00:00:00 2001
From: Lee Duncan <lduncan@suse.com>
Date: Thu, 25 Jun 2020 10:04:40 -0700
Subject: [PATCH 8/9] Use stat() not lstat() to find link target.
The test was backwards? We are trying to find what the
link points at, not info about the link.
Signed-off-by: Lee Duncan <lduncan@suse.com>
---
test/test.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/test.c b/test/test.c
index f63e346..aea34c1 100644
--- a/test/test.c
+++ b/test/test.c
@@ -165,7 +165,7 @@ static int path_is_dir(const char *path)
{
struct stat astats;
- if ((lstat(path, &astats)) != 0)
+ if ((stat(path, &astats)) != 0)
goto direrr;
if (S_ISDIR(astats.st_mode))
--
1.8.3.1

View File

@ -0,0 +1,25 @@
From b7d5488a0a7b392842ae7ff988a6615eab32a95e Mon Sep 17 00:00:00 2001
From: Lee Duncan <lduncan@suse.com>
Date: Mon, 29 Jun 2020 10:11:02 -0700
Subject: [PATCH 9/9] path_is_file() should call stat(), not lstat()
---
lib/sysfs_utils.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/sysfs_utils.c b/lib/sysfs_utils.c
index 4fa10f7..4261eae 100644
--- a/lib/sysfs_utils.c
+++ b/lib/sysfs_utils.c
@@ -316,7 +316,7 @@ int sysfs_path_is_file(const char *path)
errno = EINVAL;
return 1;
}
- if ((lstat(path, &astats)) != 0) {
+ if ((stat(path, &astats)) != 0) {
dprintf("stat() failed\n");
return 1;
}
--
1.8.3.1

View File

@ -0,0 +1,29 @@
From 5777dc78d306f7b0ab407d666f8c9537bd8535fe Mon Sep 17 00:00:00 2001
From: Chris White <chwhite@redhat.com>
Date: Fri, 25 Jun 2021 18:00:25 +0000
Subject: [PATCH] lib: Fixed a memory leak in lib/sysfs_driver.c
- sysfs_get_driver_devices() had a case where the function returned
before the dev pointer was closed.
Warned-by: covscan
Signed-off-by: Chris White <chwhite@redhat.com>
---
lib/sysfs_driver.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/lib/sysfs_driver.c b/lib/sysfs_driver.c
index a0b9dd5..13c33cf 100644
--- a/lib/sysfs_driver.c
+++ b/lib/sysfs_driver.c
@@ -252,6 +252,7 @@ struct dlist *sysfs_get_driver_devices(struct sysfs_driver *drv)
if (!drv->devices) {
dprintf("Error creating device list\n");
sysfs_close_list(linklist);
+ sysfs_close_device(dev);
return NULL;
}
}
--
2.27.0

View File

@ -0,0 +1,38 @@
From e2267a5def65380db738e434da4a3920e6136f95 Mon Sep 17 00:00:00 2001
From: Chris White <chwhite@redhat.com>
Date: Fri, 25 Jun 2021 17:55:00 +0000
Subject: [PATCH] lib: Fixed memory leaks in lib/sysfs_device.c
- sysfs_open_device_tree() has two case where the function returns
before the devlist pointer is closed.
Warned-by: covscan
Signed-off-by: Chris White <chwhite@redhat.com>
---
lib/sysfs_device.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lib/sysfs_device.c b/lib/sysfs_device.c
index 5f815f9..78ed48e 100644
--- a/lib/sysfs_device.c
+++ b/lib/sysfs_device.c
@@ -247,6 +247,7 @@ struct sysfs_device *sysfs_open_device_tree(const char *path)
if (new == NULL) {
dprintf("Error opening device tree at %s\n",
cur->path);
+ sysfs_close_device(devlist);
sysfs_close_device_tree(rootdev);
return NULL;
}
@@ -257,7 +258,7 @@ struct sysfs_device *sysfs_open_device_tree(const char *path)
dlist_unshift_sorted(rootdev->children, new, sort_list);
}
}
-
+ sysfs_close_device(devlist);
return rootdev;
}
--
2.27.0

View File

@ -0,0 +1,62 @@
From 9a4aac68658a61df1c97ecdd7d9a9e67f572fb3e Mon Sep 17 00:00:00 2001
From: Chris White <chwhite@redhat.com>
Date: Fri, 25 Jun 2021 17:32:10 +0000
Subject: [PATCH] lib: Fixed memory leaks in lib/sysfs_attr.c
- read_dir_links() has a case where the function returns before
closing the dir pointer.
- sysfs_read_dir_subdirs() has a case where the function returns
before closing the dev pointer.
- read_dir_subdirs() has a case where the function returns before
closing the dir pointer.
- get_attributes_list() has a case where the function returns before
closing the dir pointer.
Warned-by: covscan
Signed-off-by: Chris White <chwhite@redhat.com>
---
lib/sysfs_attr.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/lib/sysfs_attr.c b/lib/sysfs_attr.c
index fe27dbe..82aacf4 100644
--- a/lib/sysfs_attr.c
+++ b/lib/sysfs_attr.c
@@ -415,6 +415,7 @@ struct dlist *read_dir_links(const char *path)
(SYSFS_NAME_LEN, sysfs_del_name);
if (!linklist) {
dprintf("Error creating list\n");
+ closedir(dir);
return NULL;
}
}
@@ -470,6 +471,7 @@ struct sysfs_device *sysfs_read_dir_subdirs(const char *path)
dir = opendir(path);
if (!dir) {
dprintf("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 char *path)
(SYSFS_NAME_LEN, sysfs_del_name);
if (!dirlist) {
dprintf("Error creating list\n");
+ closedir(dir);
return NULL;
}
}
@@ -573,6 +576,7 @@ struct dlist *get_attributes_list(struct dlist *alist, const char *path)
sysfs_del_attribute);
if (!alist) {
dprintf("Error creating list\n");
+ closedir(dir);
return NULL;
}
}
--
2.27.0

View File

@ -1,20 +1,26 @@
Name: sysfsutils
Version: 2.1.0
Release: 28
Release: 34
Summary: A set of utilities for interfacing with sysfs
License: GPLv2 and LGPLv2+
URL: http://sourceforge.net/projects/linux-diag/
Source0: http://prdownloads.sourceforge.net/linux-diag/%{name}-%{version}.tar.gz
Patch1: 0001-sysfsutils-2.0.0-class-dup.patch
Patch1: 0001-Fix-issue-with-sysfs-name-comparisons.patch
Patch2: 0002-sysfsutils-2.1.0-get_link.patch
Patch3: 0003-sysfsutils-2.1.0-manpages.patch
Patch4: 0004-sysfsutils-aarch64.patch
Patch5: 0005-sysutils-modify-GPL-path-written-in-COPYING.patch
Patch6: 0006-fix-of-FUNC_TABLE_SIZE-mentioned-in-prev-commit.patch
Patch7: 0007-Fix-compiler-complain-about-multiple-defs-of-my_stdo.patch
Patch8: 0008-Use-stat-not-lstat-to-find-link-target.patch
Patch9: 0009-path_is_file-should-call-stat-not-lstat.patch
Patch10: 0010-lib-Fixed-a-memory-leak-in-lib-sysfs_driver.c.patch
Patch11: 0011-lib-Fixed-memory-leaks-in-lib-sysfs_device.c.patch
Patch12: 0012-lib-Fixed-memory-leaks-in-lib-sysfs_attr.c.patch
Patch9000: 9000-sysutils-modify-GPL-path-written-in-COPYING.patch
BuildRequires: git gcc chrpath
BuildRequires: gcc chrpath
Provides: libsysfs libsysfs%{?_isa}
Obsoletes: libsysfs
@ -44,12 +50,15 @@ BuildArch: noarch
This contains man files for the using of sysfsutils.
%prep
%autosetup -n %{name}-%{version} -p1 -S git
%autosetup -n %{name}-%{version} -p1
%build
%configure --disable-static --libdir=/%{_lib}
%make_build
%check
make check
%install
%make_install
@ -82,6 +91,27 @@ chrpath -d $(find $RPM_BUILD_ROOT -name systool)
%changelog
* Mon May 8 2023 Jiangtian Feng <fengjiangtian@huawei.com> - 2.1.0-34
- backport community patches to fix mem leak in sysfs_attr.c, sysfs_device.c, and sysfs_driver.c
* Wed Mar 30 2022 yanglongkang <yanglongkang@h-partners.com> - 2.1.0-33
- correcting errors in 0009-path_is_file-should-call-stat-not-lstat.patch
* Fri Jul 30 2021 chenyanpanHW <chenyanpan@huawei.com> - 2.1.0-32
- DESC: delete -S git from %autosetup, and delete BuildRequires git
* Wed Nov 4 2020 lixiaokeng <lixiaokeng@huawei.com> - 2.1.0-31
- add make check
* Mon Jul 13 2020 Zhiqiang Liu <liuzhiqiang26@huawei.com> - 2.1.0-30
- backport upstream bugfix patches
* Tue Jun 30 2020 volcanodragon <linfeilong@huawei.com> - 2.1.0-29
- Type:enhancemnet
- ID:NA
- SUG:restart
- DESC:rename patches
* Fri Jan 10 2020 Huangzheng <huangzheng22@huawei.com> - 2.1.0-28
- Type:enhancemnet
- ID:NA