From 949abd72c260c70b5ae198ea51b00b14cce3b503 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Wed, 17 Aug 2022 12:52:12 +0200 Subject: [PATCH 1/5] build: Check for large file support Check whether the system has LFS, and if so enable it. This should be ABI safe for the shared library as it does not expose any problematic type. Signed-off-by: Guillem Jover --- configure.ac | 3 +++ 1 file changed, 3 insertions(+) diff --git a/configure.ac b/configure.ac index 5ee5a04..9c7c47f 100644 --- a/configure.ac +++ b/configure.ac @@ -54,6 +54,9 @@ AC_PROG_CC AC_PROG_INSTALL AC_PROG_MAKE_SET +# Checks for operating system services and capabilities. +AC_SYS_LARGEFILE + # Checks for header files. AC_HEADER_DIRENT AC_CHECK_HEADERS([fcntl.h malloc.h stdlib.h string.h unistd.h]) From 3af782278fbef4736c32d5399a4a1b583be59f94 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Wed, 17 Aug 2022 12:54:28 +0200 Subject: [PATCH 2/5] test: Limit dlist test to 10 iterations Having a test that never returns is not very nice, as it makes trying to run it during build or on a CI system hang. Signed-off-by: Guillem Jover --- test/dlist_test.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/dlist_test.c b/test/dlist_test.c index e7f3d1e..a5365b6 100644 --- a/test/dlist_test.c +++ b/test/dlist_test.c @@ -68,7 +68,8 @@ int main (void) Dlist *list; Simple *s1,*s2,*s3,*stemp; Complex *c1,*c2,*c3, *c4, *ctemp, *cfound; - while(1) + int count = 10; + while(count--) { s1=simple_maker(1,"one"); s2=simple_maker(2,"two"); From c139bfadd91ff75d2e2a9bbfd3726bb22000bd9f Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Wed, 17 Aug 2022 13:05:20 +0200 Subject: [PATCH 3/5] lib: Reset freed value to avoid double-free or use-after-free Follow the same pattern in sysfs_read_attribute() as the rest of the code, and protect against wrong usage of the freed pointer. Signed-off-by: Guillem Jover --- lib/sysfs_attr.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/sysfs_attr.c b/lib/sysfs_attr.c index ccf829f..cef33ae 100644 --- a/lib/sysfs_attr.c +++ b/lib/sysfs_attr.c @@ -179,6 +179,7 @@ int sysfs_read_attribute(struct sysfs_attribute *sysattr) return 0; } free(sysattr->value); + sysattr->value = NULL; } sysattr->len = length; close(fd); From 44a8a9ab6280b68f716b8483b82ab336e07134b4 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Wed, 17 Aug 2022 13:11:03 +0200 Subject: [PATCH 4/5] lib: Remove unused assignment in get_dev_attributes_list() The variable attr is only used in the other if branch, to check whether it is NULL. Signed-off-by: Guillem Jover --- lib/sysfs_attr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sysfs_attr.c b/lib/sysfs_attr.c index cef33ae..8765731 100644 --- a/lib/sysfs_attr.c +++ b/lib/sysfs_attr.c @@ -630,7 +630,7 @@ struct dlist *get_dev_attributes_list(void *dev) else add_attribute(dev, file_path); } else - attr = add_attribute(dev, file_path); + add_attribute(dev, file_path); } } closedir(dir); From bb3824454b11660f4ddcd10fce93367a153f1cc7 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Wed, 17 Aug 2022 13:11:59 +0200 Subject: [PATCH 5/5] lib: Remove unused variable assignment in sysfs_write_attribute() The return value from write is never used nor checked, as we close() and immediately return. Signed-off-by: Guillem Jover --- lib/sysfs_attr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sysfs_attr.c b/lib/sysfs_attr.c index 8765731..8d2d0fc 100644 --- a/lib/sysfs_attr.c +++ b/lib/sysfs_attr.c @@ -256,7 +256,7 @@ int sysfs_write_attribute(struct sysfs_attribute *sysattr, * restore the old value if one available */ if (sysattr->method & SYSFS_METHOD_SHOW) { - length = write(fd, sysattr->value, sysattr->len); + (void)write(fd, sysattr->value, sysattr->len); close(fd); return -1; }