Compare commits

..

10 Commits

Author SHA1 Message Date
openeuler-ci-bot
e49c795fa8
!34 correct lisence
From: @mszjaas 
Reviewed-by: @swf504 
Signed-off-by: @swf504
2024-08-01 11:30:54 +00:00
EulerOSWander
7f156e0980 correct lisence
Signed-off-by: zhangjian <zhangjian496@huawei.com>
2024-08-01 17:27:54 +08:00
openeuler-ci-bot
2b2aebd45d
!27 fix mem leak in lib/sysfs_device.c and lib/sysfs_attr.c
From: @fjt42 
Reviewed-by: @swf504 
Signed-off-by: @swf504
2023-05-08 02:02:01 +00:00
Jiangtian Feng
542323c36e backport community patches to fix mem leak in lib/sysfs_device.c and lib/sysfs_attr.c
Signed-off-by: Jiangtian Feng <fengjiangtian@huawei.com>
2023-05-08 09:15:24 +08:00
openeuler-ci-bot
f36c5b93d4
!26 [sync] PR-24: 修复lib/sysfs_driver.c中内存泄露问题
From: @openeuler-sync-bot 
Reviewed-by: @liuzhiqiang26 
Signed-off-by: @liuzhiqiang26
2022-11-01 07:08:37 +00:00
lihaoxiang
03ff80c5eb fixed a memory leak in lib/sysfs_driver.c
(cherry picked from commit 1328ca91f409dad0ef94a85537b349654b16379a)
2022-11-01 14:37:50 +08:00
openeuler-ci-bot
c46c1560db !19 update to 2.1.1
From: @markeryang
Reviewed-by: @wubo009
Signed-off-by: @wubo009
2021-11-26 01:24:17 +00:00
markeryang
d0d0800ffd update to 2.1.1 2021-11-25 22:10:45 +08:00
openeuler-ci-bot
481af9701e !13 sysfsutils delete -S git from %autosetup, and delete BuildRequires git
From: @chenyanpanHW
Reviewed-by: @liuzhiqiang26
Signed-off-by: @liuzhiqiang26
2021-08-01 12:47:53 +00:00
chenyanpanHW
b40a33dc98
delete -S git from %autosetup, and delete BuildRequires git 2021-07-30 23:37:13 +08:00
15 changed files with 160 additions and 3093 deletions

View File

@ -1,60 +0,0 @@
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

@ -0,0 +1,28 @@
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
@@ -255,6 +255,7 @@ struct dlist *sysfs_get_driver_devices(struct sysfs_driver *drv)
if (!drv->devices) {
dbg_printf("Error creating device list\n");
sysfs_close_list(linklist);
+ sysfs_close_device(dev);
return NULL;
}
}
--
2.37.0.windows.1

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) {
dbg_printf("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

@ -1,164 +0,0 @@
diff -upr sysfsutils-2.1.0-old/lib/sysfs_utils.c sysfsutils-2.1.0/lib/sysfs_utils.c
--- sysfsutils-2.1.0-old/lib/sysfs_utils.c 2006-08-07 07:08:01.000000000 +0200
+++ sysfsutils-2.1.0/lib/sysfs_utils.c 2008-05-13 07:42:50.000000000 +0200
@@ -117,84 +117,104 @@ int sysfs_get_link(const char *path, cha
{
char devdir[SYSFS_PATH_MAX];
char linkpath[SYSFS_PATH_MAX];
- char temp_path[SYSFS_PATH_MAX];
- char *d = NULL, *s = NULL;
- int slashes = 0, count = 0;
+ char *d, *s;
+ int count;
if (!path || !target || len == 0) {
errno = EINVAL;
return -1;
}
- memset(devdir, 0, SYSFS_PATH_MAX);
- memset(linkpath, 0, SYSFS_PATH_MAX);
- memset(temp_path, 0, SYSFS_PATH_MAX);
- safestrcpy(devdir, path);
-
- if ((readlink(path, linkpath, SYSFS_PATH_MAX)) < 0) {
+ count = readlink(path, linkpath, SYSFS_PATH_MAX);
+ if (count < 0)
return -1;
- }
- d = linkpath;
+ else
+ linkpath[count] = '\0';
/*
* Three cases here:
* 1. relative path => format ../..
* 2. absolute path => format /abcd/efgh
* 3. relative path _from_ this dir => format abcd/efgh
*/
- switch (*d) {
- case '.':
+ if (*linkpath == '/') {
+ /* absolute path - copy as is */
+ safestrcpymax(target, linkpath, len);
+ return 0;
+ }
+
+ safestrcpy(devdir, path);
+ s = strrchr(devdir, '/');
+ if (s == NULL)
+ s = devdir - 1;
+ d = linkpath;
+ while (*d == '.') {
+ if (*(d+1) == '/') {
/*
* handle the case where link is of type ./abcd/xxx
*/
- safestrcpy(temp_path, devdir);
- if (*(d+1) == '/')
- d += 2;
- else if (*(d+1) == '.')
- goto parse_path;
- s = strrchr(temp_path, '/');
- if (s != NULL) {
- *(s+1) = '\0';
- safestrcat(temp_path, d);
- } else {
- safestrcpy(temp_path, d);
- }
- safestrcpymax(target, temp_path, len);
- break;
+ d += 2;
+ while (*d == '/')
+ d++;
+ continue;
+ } else if (*(d+1) != '.' || *(d+2) != '/')
/*
- * relative path, getting rid of leading "../.."
+ * relative path from this directory, starting
+ * with a hidden directory
*/
-parse_path:
- while (*d == '/' || *d == '.') {
- if (*d == '/')
- slashes++;
- d++;
- }
- d--;
- s = &devdir[strlen(devdir)-1];
- while (s != NULL && count != (slashes+1)) {
+ break;
+
+ /*
+ * relative path, getting rid of leading "../.."; must
+ * be careful here since any path component of devdir
+ * could be a symlink again
+ */
+ for (;;) {
+ while (s > devdir && *s == '/') {
s--;
- if (*s == '/')
- count++;
+ if (*s == '.'
+ && (s == devdir || *(s-1) == '/'))
+ s--;
}
- safestrcpymax(s, d, (SYSFS_PATH_MAX-strlen(devdir)));
- safestrcpymax(target, devdir, len);
- break;
- case '/':
- /* absolute path - copy as is */
- safestrcpymax(target, linkpath, len);
- break;
- default:
- /* relative path from this directory */
- safestrcpy(temp_path, devdir);
- s = strrchr(temp_path, '/');
- if (s != NULL) {
- *(s+1) = '\0';
- safestrcat(temp_path, linkpath);
- } else {
- safestrcpy(temp_path, linkpath);
+ *(s+1) = '\0';
+ if (*devdir == '\0' || sysfs_path_is_link(devdir))
+ /*
+ * condition will be true eventually
+ * because we already know that all
+ * but the last component of path
+ * resolve to a directory
+ */
+ break;
+ if (sysfs_get_link(devdir, devdir, SYSFS_PATH_MAX))
+ return -1;
+ s = devdir + strlen(devdir) - 1;
+ }
+ while (s >= devdir) {
+ if (*s == '/') {
+ if (*(s+1) != '.' || *(s+2) != '.'
+ || *(s+3) != '\0') {
+ d += 3;
+ while (*d == '/')
+ d++;
+ } else
+ s += 2;
+ break;
}
- safestrcpymax(target, temp_path, len);
+ s--;
+ }
+ if (s < devdir || *(s+1) == '\0')
+ break;
}
+
+ /*
+ * appending to devdir a slash and the (possibly shortened)
+ * relative path to the link source
+ */
+ s++;
+ if (s > devdir && *s == '\0')
+ *s++ = '/';
+ *s = '\0';
+ safestrcpymax(s, d, SYSFS_PATH_MAX-(s-devdir));
+ safestrcpymax(target, devdir, len);
return 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) {
dbg_printf("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) {
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 char *path)
(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 dlist *alist, const char *path)
sysfs_del_attribute);
if (!alist) {
dbg_printf("Error creating list\n");
+ closedir(dir);
return NULL;
}
}
--
2.27.0

View File

@ -1,12 +0,0 @@
diff -urpN sysfsutils-2.1.0.orig/systool.1 sysfsutils-2.1.0/systool.1
--- sysfsutils-2.1.0.orig/systool.1 2011-03-22 18:15:40.775891943 +0100
+++ sysfsutils-2.1.0/systool.1 2011-03-22 18:16:05.158970786 +0100
@@ -14,7 +14,7 @@ classes, and root devices.
.P
When
.I device
-is supplied, the information reqested by
+is supplied, the information requested by
.I options
is shown only for the specified device, otherwise all present devices
are displayed.

File diff suppressed because it is too large Load Diff

View File

@ -1,31 +0,0 @@
From bcb67a67348ebe154d6bf2d426e0a0b5c18630be Mon Sep 17 00:00:00 2001
From: Huangzheng <huangzheng22@huawei.com>
Date: Fri, 10 Jan 2020 16:27:37 +0800
Subject: [PATCH] sysfsutils: modify GPL path written in COPYING
Openeuler has packaged the GPL and LGPL into usr/share/licenses/sysfsutils,
so we need modify COPYING file.
Signed-off-by: Huangzheng <huangzheng22@huawei.com>
---
COPYING | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/COPYING b/COPYING
index 39cac23..c0b5638 100644
--- a/COPYING
+++ b/COPYING
@@ -3,9 +3,9 @@ The commands and utilities under the "test" directory are licensed under the
GNU General Public License (GPL) Version 2, June 1991. The full text of the
GPL is located at:
-sysfsutils/cmd/GPL
+/usr/share/licenses/sysfsutils/GPL
The sysfs library is licensed under the GNU Lesser Public License (LGPL)
Version 2.1, February 1999. The full text of the LGPL is located at:
-sysfsutils/lib/LGPL
+/usr/share/licenses/sysfsutils/LGPL
--
2.19.1

View File

@ -1,28 +0,0 @@
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

@ -1,43 +0,0 @@
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

@ -1,29 +0,0 @@
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

@ -1,25 +0,0 @@
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..0257ffa 100644
--- a/lib/sysfs_utils.c
+++ b/lib/sysfs_utils.c
@@ -293,7 +293,7 @@ int sysfs_path_is_link(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

Binary file not shown.

View File

@ -1,23 +1,17 @@
Name: sysfsutils
Version: 2.1.0
Release: 31
Version: 2.1.1
Release: 4
Summary: A set of utilities for interfacing with sysfs
License: GPLv2 and LGPLv2+
URL: http://sourceforge.net/projects/linux-diag/
License: GPL-2.0-only
URL: https://github.com/linux-ras/sysfsutils
Source0: http://prdownloads.sourceforge.net/linux-diag/%{name}-%{version}.tar.gz
Source0: https://github.com/linux-ras/sysfsutils/archive/v%{version}.tar.gz
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
Patch1: 0001-lib-Fixed-a-memory-leak-in-lib-sysfs_driver.patch
Patch2: 0002-lib-Fixed-memory-leaks-in-lib-sysfs_device.c.patch
Patch3: 0003-lib-Fixed-memory-leaks-in-lib-sysfs_attr.c.patch
BuildRequires: git gcc chrpath
BuildRequires: gcc chrpath autoconf automake make libtool
Provides: libsysfs libsysfs%{?_isa}
Obsoletes: libsysfs
@ -30,7 +24,7 @@ provides a tree of system devices.
%package devel
Summary: Including header files and library for the developing of sysfsutils
License: LGPLv2+
License: LGPL-2.1-or-later
Requires: sysfsutils = %{version}-%{release}
Provides: libsysfs-devel
Obsoletes: libsysfs-devel
@ -47,9 +41,10 @@ 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
./autogen
%configure --disable-static --libdir=/%{_lib}
%make_build
@ -71,9 +66,8 @@ chrpath -d $(find $RPM_BUILD_ROOT -name systool)
%files
%license COPYING cmd/GPL lib/LGPL
%doc README NEWS ChangeLog
%doc README
%{_bindir}/systool
%{_bindir}/get_module
/%{_lib}/libsysfs.so.*
%files devel
@ -81,6 +75,7 @@ chrpath -d $(find $RPM_BUILD_ROOT -name systool)
%{_includedir}/sysfs/libsysfs.h
%{_includedir}/sysfs/dlist.h
/%{_lib}/libsysfs.so
/%{_lib}/pkgconfig/libsysfs.pc
%files help
%{_mandir}/man1/systool.1.gz
@ -88,6 +83,24 @@ chrpath -d $(find $RPM_BUILD_ROOT -name systool)
%changelog
* Tue Jul 30 2024 zhangjian <zhangjian496@huawei.com> - 2.1.1-4
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:correct lisence
* Sat May 6 2023 Jiangtian Feng <fengjiangtian@huawei.com> - 2.1.1-3
- backport community patches to fix mem leak in lib/sysfs_device.c and lib/sysfs_attr.c
* Tue Nov 1 2022 lihaoxiang <lihaoxiang9@huawei.com> - 2.1.1-2
- fixed a memory leak in lib/sysfs_driver.c
* Thu Nov 25 2021 yanglongkang <yanglongkang@huawei.com> - 2.1.1-1
- update to 2.1.1
* 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

BIN
v2.1.1.tar.gz Normal file

Binary file not shown.