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
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to