From 744befa9faa3446ff6bf0627cadb6a3addae1dd1 Mon Sep 17 00:00:00 2001 From: Lee Duncan 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 --- 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