]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-device: do not trigger assertion by a bad udev rules 30040/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 15 Nov 2023 17:27:19 +0000 (02:27 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 15 Nov 2023 17:32:12 +0000 (02:32 +0900)
The assertion can be triggered by bad `$attr{[<subsys>/<sysname>]<attribute>}`
formatting. That's not a programmer's error, but a runtime error.

Prompted by #30029.

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

index 75725a75b3d6a33ba50fb485fb44a9f0baabee09..2fbc619a34d3cd4da057bd356c24acbe5eb21f08 100644 (file)
@@ -422,8 +422,13 @@ _public_ int sd_device_new_from_subsystem_sysname(
         int r;
 
         assert_return(ret, -EINVAL);
-        assert_return(path_is_normalized(subsystem), -EINVAL);
-        assert_return(path_is_normalized(sysname), -EINVAL);
+        assert_return(subsystem, -EINVAL);
+        assert_return(sysname, -EINVAL);
+
+        if (!path_is_normalized(subsystem))
+                return -EINVAL;
+        if (!path_is_normalized(sysname))
+                return -EINVAL;
 
         /* translate sysname back to sysfs filename */
         name = strdupa_safe(sysname);