From: Kevin Lo Date: Sat, 4 Apr 2015 16:59:26 +0000 (+0800) Subject: netdev-bsd: Fix sign extension bug in ifr_flags on FreeBSD. X-Git-Tag: v2.3.2~18 X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Fovs.git;a=commitdiff_plain;h=ad5c52ec548c8ee2ace4afe8fd14d7d437485433 netdev-bsd: Fix sign extension bug in ifr_flags on FreeBSD. FreeBSD fills the int return value with ifr_flagshigh in the high 16 bits and ifr_flags in the low 16 bits rather than blindly promoting ifr_flags to an int, which will preserve the sign. This commit makes sure the flags returned isn't negative and apply mask 0xffff to flags. Signed-off-by: Kevin Lo Signed-off-by: Ben Pfaff --- diff --git a/lib/netdev-bsd.c b/lib/netdev-bsd.c index 85f3b2185..671de3745 100644 --- a/lib/netdev-bsd.c +++ b/lib/netdev-bsd.c @@ -1771,7 +1771,7 @@ static int ifr_get_flags(const struct ifreq *ifr) { #ifdef HAVE_STRUCT_IFREQ_IFR_FLAGSHIGH - return (ifr->ifr_flagshigh << 16) | ifr->ifr_flags; + return (ifr->ifr_flagshigh << 16) | (ifr->ifr_flags & 0xffff); #else return ifr->ifr_flags; #endif @@ -1780,9 +1780,11 @@ ifr_get_flags(const struct ifreq *ifr) static void ifr_set_flags(struct ifreq *ifr, int flags) { - ifr->ifr_flags = flags; #ifdef HAVE_STRUCT_IFREQ_IFR_FLAGSHIGH + ifr->ifr_flags = flags & 0xffff; ifr->ifr_flagshigh = flags >> 16; +#else + ifr->ifr_flags = flags; #endif }