]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-device: reject empty driver name
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 5 May 2021 15:02:49 +0000 (17:02 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 6 May 2021 12:51:08 +0000 (14:51 +0200)
If ":" was the last char in the string, we would call access() on ".../drivers/", which
would pass. It probably doesn't matter, but let's reject this anyway.

(cherry picked from commit 52a89a5f08230439f07c043d59ded1270842137b)

src/libsystemd/sd-device/sd-device.c

index c041660faf3814b39c071c174eddd8268fca29c9..d82f01a164682f28fd4001ad94f3705301228cb8 100644 (file)
@@ -274,7 +274,7 @@ _public_ int sd_device_new_from_subsystem_sysname(sd_device **ret, const char *s
                 const char *subsys, *sep;
 
                 sep = strchr(sysname, ':');
-                if (sep) {
+                if (sep && sep[1] != '\0') { /* Require ":" and something non-empty after that. */
                         subsys = memdupa_suffix0(sysname, sep - sysname);
 
                         if (snprintf_ok(syspath, sizeof syspath, "/sys/subsystem/%s/drivers/%s", subsys, sep + 1) &&