[PATCH] ifplugd
Denys Vlasenko
vda.linux at googlemail.com
Fri Apr 2 05:03:29 UTC 2010
On Wednesday 31 March 2010 12:58, Maxim Kryžanovský wrote:
> > 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
More information about the busybox
mailing list