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)
Thu, Sep 19, 2:21 AM
Unknown Object (File)
Wed, Sep 11, 3:41 PM
Unknown Object (File)
Thu, Sep 5, 8:48 AM
Unknown Object (File)
Aug 31 2024, 3:29 PM
Unknown Object (File)
Aug 23 2024, 6:39 PM
Unknown Object (File)
Jul 28 2024, 8:00 AM
Unknown Object (File)
Jul 14 2024, 8:08 PM
Unknown Object (File)
Jul 10 2024, 5:26 AM
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.