From be3b317705cbfdd694deae92db7f6e0458e702c0 Mon Sep 17 00:00:00 2001 From: Wenchao Hao Date: Mon, 30 Nov 2020 21:41:56 +0800 Subject: sysfs: Verify parameter of sysfs_device_get() In sysfs_device_get() we should firstly check whether devpath pointer is NULL before accessing it Signed-off-by: Wenchao Hao Signed-off-by: Zhiqiang Liu Signed-off-by: Wu Bo --- usr/sysfs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'usr') diff --git a/usr/sysfs.c b/usr/sysfs.c index 8d37c69..7f26572 100644 --- a/usr/sysfs.c +++ b/usr/sysfs.c @@ -168,9 +168,11 @@ struct sysfs_device *sysfs_device_get(const char *devpath) int len; char *pos; + if (!devpath) + return NULL; + /* we handle only these devpathes */ - if (devpath != NULL && - strncmp(devpath, "/devices/", 9) != 0 && + if (strncmp(devpath, "/devices/", 9) != 0 && strncmp(devpath, "/subsystem/", 11) != 0 && strncmp(devpath, "/module/", 8) != 0 && strncmp(devpath, "/bus/", 5) != 0 && -- cgit v1.2.1