summaryrefslogtreecommitdiff
path: root/udev
diff options
context:
space:
mode:
Diffstat (limited to 'udev')
-rw-r--r--udev/lib/libudev-device.c2
-rw-r--r--udev/udevadm-test.c8
2 files changed, 6 insertions, 4 deletions
diff --git a/udev/lib/libudev-device.c b/udev/lib/libudev-device.c
index 1a9d0a1e69..e13cbe554b 100644
--- a/udev/lib/libudev-device.c
+++ b/udev/lib/libudev-device.c
@@ -303,7 +303,7 @@ struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *
/* path is not a root directory */
subdir = &syspath[len+1];
pos = strrchr(subdir, '/');
- if (pos == NULL || pos < &subdir[2]) {
+ if (pos == NULL || pos[1] == '\0' || pos < &subdir[2]) {
dbg(udev, "not a subdir :%s\n", syspath);
return NULL;
}
diff --git a/udev/udevadm-test.c b/udev/udevadm-test.c
index 664d72f6d3..c53c273295 100644
--- a/udev/udevadm-test.c
+++ b/udev/udevadm-test.c
@@ -94,12 +94,14 @@ int udevadm_test(struct udev *udev, int argc, char *argv[])
if (strncmp(syspath, udev_get_sys_path(udev), strlen(udev_get_sys_path(udev))) != 0) {
util_strlcpy(filename, udev_get_sys_path(udev), sizeof(filename));
util_strlcat(filename, syspath, sizeof(filename));
- syspath = filename;
+ } else {
+ util_strlcpy(filename, syspath, sizeof(filename));
}
+ util_remove_trailing_chars(filename, '/');
- dev = udev_device_new_from_syspath(udev, syspath);
+ dev = udev_device_new_from_syspath(udev, filename);
if (dev == NULL) {
- fprintf(stderr, "unable to open device '%s'\n", syspath);
+ fprintf(stderr, "unable to open device '%s'\n", filename);
rc = 2;
goto exit;
}