HomeFreeBSD

ifconfig: Avoid issues with trying to negate unsigned values.

Description

ifconfig: Avoid issues with trying to negate unsigned values.

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),

|                                 ^

Reviewed by: emaste
Differential Revision: https://reviews.freebsd.org/D40608

Details

Provenance
jhbAuthored on Jun 19 2023, 5:37 PM
Reviewer
emaste
Differential Revision
D40608: ifconfig: Avoid issues with trying to negate unsigned values.
Parents
rGe60316d1eac9: x86: Add defines for a couple of thermal and PM bits
Branches
Unknown
Tags
Unknown