• Mike Frysinger's avatar
    use sockaddr_storage everywhere · 5c9e1e76
    Mike Frysinger authored
    Not all sockaddr structs have the same alignment.  Instead, it depends
    on the fields contained in it.  The way net-tools has written things
    though, it accepts sockaddr* everywhere which has 16bit alignment, even
    though it will cast it to other sockaddr types that have higher alignment.
    For example, `route` can crash on alpha because it declares sockaddr on
    the stack, but then casts it up to sockaddr_in6 (which has 32bits).
    It's also bad storage wise as we might try to cast the sockaddr to a type
    that is larger than sockaddr which means clobbering the stack.
    Instead, lets rewrite all the APIs to take a sockaddr_storage.  This is
    guaranteed to have both the maximum alignment and size requirements for
    all other sockaddr types.  Now we can safely cast that pointer to any
    other sockaddr type and not worry about it.  It also has the nice effect
    of deleting a lot of casts in a lot of places when we only need the type
    of family.
    The vast majority of changes here are mechanical.  There are a few places
    where we have to memcpy between a dedicated sockaddr_storage and a smaller
    struct because we're using an external embedded type (like arpreq).
    URL: https://bugs.gentoo.org/558436
arp.c 21 KB