sd-device: refuse earlier when too long ifname is passed to sd_device_new_from_ifname()

Otherwise, alloca() called in strjoina() may trigger assertion.

This partially reverts 3652891c39.
The commit mistakenly dropped the check.
This commit is contained in:
Yu Watanabe
2024-08-26 06:33:42 +09:00
parent 1937f5105d
commit 55e35a4d59

View 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)