Page MenuHomeFreeBSD

ifconfig: Avoid issues with trying to negate unsigned values.
ClosedPublic

Authored by jhb on Jun 19 2023, 5:06 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Jun 9, 9:40 AM
Unknown Object (File)
Sat, Jun 8, 9:12 PM
Unknown Object (File)
Fri, Jun 7, 10:47 PM
Unknown Object (File)
Fri, Jun 7, 10:35 PM
Unknown Object (File)
Apr 26 2024, 10:17 PM
Unknown Object (File)
Apr 26 2024, 10:17 PM
Unknown Object (File)
Apr 26 2024, 10:17 PM
Unknown Object (File)
Apr 26 2024, 8:04 PM
Subscribers

Details

Summary

The if_flags and if_cap fields hold a bitmask of flags. If a flag is
the MSB of the field, then the logic in setifflags and setifcap which
uses a < 0 check does the wrong thing (it tries to clear the flag
rather than setting it). Also, trying to use -<FOO> doesn't actually
work as the result is a nop. To fix, stop overloading setifcap and
setifflags and instead add new dedicated action functions clearifcap
and clearifflags for clearing a flag. The value passed in the
argument to the command is now always the raw flag.

This was reported by a GCC warning after raising WARNS:

sbin/ifconfig/ifconfig.c:2061:33: error: integer overflow in expression '-2147483648' of type 'int' results in '-2147483648' [-Werror=overflow]
2061 | DEF_CMD("-txtlsrtlmt", -IFCAP_TXTLS_RTLMT, setifcap),

|                                 ^

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

jhb requested review of this revision.Jun 19 2023, 5:06 PM
emaste added inline comments.
sbin/ifconfig/ifvlan.c
294–295

these should probably be in the opposite order (independent of your change)

This revision is now accepted and ready to land.Jun 19 2023, 5:12 PM
sbin/ifconfig/ifvlan.c
294–295

Yeah, I noticed but just left it as-is.