> > > Is this safe?
> > >
> > > if (strncmp(G.iface, RTA_DATA(attr), len) == 0)
> > >
> > > What if RTA_DATA(attr) = "if", len = 2, and G.iface = "if0"?
> > > Or does kernel pass attr with NUL included?
>
> > Yes, it is not safe. It needs to compare their lengths:
> > int iface_len = strlen(G.iface);
> > if (iface_len == len && strncmp(G.iface, RTA_DATA(attr), len) == 0)
>
> Ok, now what if RTA_DATA(attr) = "if\0", len = 3, and G.iface = "if"?
> Your code will think that strings aren't equal. Maybe
>
> if (iface_len <= len && strncmp(G.iface, RTA_DATA(attr), len) == 0)
>
> --
> vda
>
>
>
Hi Denis.
The kernel pass attr with NUL included, but I could not determine
whether does this always. If so, the NUL can be omitted from the total
length to avoid the need to compare strings with different lengths.
diff --git a/networking/ifplugd.c b/networking/ifplugd.c
index 41b04c4..dcb6d4d 100644
--- a/networking/ifplugd.c
+++ b/networking/ifplugd.c
@@ -525,10 +525,10 @@ static NOINLINE int check_existence_through_netlink(void)
while (RTA_OK(attr, attr_len)) {
if (attr->rta_type == IFLA_IFNAME) {
- int len = RTA_PAYLOAD(attr);
+ int len = RTA_PAYLOAD(attr) - 1;
if (len > IFNAMSIZ)
len = IFNAMSIZ;
- if (iface_len <= len
+ if (iface_len == len
&& strncmp(G.iface,
RTA_DATA(attr), len) == 0
) {
G.iface_exists =
(mhdr->nlmsg_type == RTM_NEWLINK);
Also attached is a fix to 'ENABLE_FEATURE_PIDFILE is not set'.
--
max
diff --git a/networking/ifplugd.c b/networking/ifplugd.c
index 41b04c4..52264f6 100644
--- a/networking/ifplugd.c
+++ b/networking/ifplugd.c
@@ -646,7 +646,9 @@ int ifplugd_main(int argc UNUSED_PARAM, char **argv)
xmove_fd(netlink_open(), netlink_fd);
}
+#if ENABLE_FEATURE_PIDFILE
write_pidfile(pidfile_name);
+#endif
/* this can't be moved before socket creation */
if (!(opts & FLAG_NO_SYSLOG)) {
@@ -794,6 +796,8 @@ int ifplugd_main(int argc UNUSED_PARAM, char **argv)
}
exiting:
+#if ENABLE_FEATURE_PIDFILE
remove_pidfile(pidfile_name);
+#endif
bb_error_msg_and_die("exiting");
}
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox