Re: [PATCH] ifplugd
Maxim Kryžanovský
xmaks at email.cz
Wed Apr 7 18:02:29 UTC 2010
> > > 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ifplugd.pidfile.patch
Type: text/x-patch
Size: 611 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20100407/838ea1a2/attachment.bin>
More information about the busybox
mailing list