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
F115064514: D40608.id.diff
Sun, Apr 20, 3:23 AM
F115063584: D40608.id123438.diff
Sun, Apr 20, 3:10 AM
F115059419: D40608.id.diff
Sun, Apr 20, 2:14 AM
F115056576: D40608.id123438.diff
Sun, Apr 20, 1:35 AM
F115054803: D40608.diff
Sun, Apr 20, 1:11 AM
Unknown Object (File)
Sat, Mar 22, 11:16 PM
Unknown Object (File)
Jan 27 2025, 7:17 AM
Unknown Object (File)
Jan 22 2025, 4:05 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.