]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-device: refuse earlier when too long ifname is passed to sd_device_new_from_ifname()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 25 Aug 2024 21:33:42 +0000 (06:33 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 27 Aug 2024 20:18:14 +0000 (05:18 +0900)
Otherwise, alloca() called in strjoina() may trigger assertion.

This partially reverts 3652891c3904992e21739e9bfb004073841db63c.
The commit mistakenly dropped the check.

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

index dafda626f077d0b15d8778139aa76da017b0e4aa..3d683fb280269e9499d189550b941219f3629b61 100644 (file)
@@ -345,9 +345,11 @@ _public_ int sd_device_new_from_ifname(sd_device **ret, const char *ifname) {
         assert_return(ret, -EINVAL);
         assert_return(ifname, -EINVAL);
 
-        r = device_new_from_main_ifname(ret, ifname);
-        if (r >= 0)
-                return r;
+        if (ifname_valid(ifname)) {
+                r = device_new_from_main_ifname(ret, ifname);
+                if (r >= 0)
+                        return r;
+        }
 
         r = rtnl_resolve_ifname_full(NULL, RESOLVE_IFNAME_ALTERNATIVE | RESOLVE_IFNAME_NUMERIC, ifname, &main_name, NULL);
         if (r < 0)