Page MenuHomeFreeBSD

netlink: Avoid undefined behaviour
ClosedPublic

Authored by emaste on May 22 2026, 1:05 AM.
Tags
None
Referenced Files
F160535598: D57158.id178382.diff
Thu, Jun 25, 10:47 AM
F160535575: D57158.id178382.diff
Thu, Jun 25, 10:47 AM
F160533404: D57158.id.diff
Thu, Jun 25, 10:22 AM
F160529424: D57158.id178387.diff
Thu, Jun 25, 9:32 AM
F160529409: D57158.id178387.diff
Thu, Jun 25, 9:32 AM
F160512168: D57158.diff
Thu, Jun 25, 6:13 AM
Unknown Object (File)
Wed, Jun 17, 12:51 AM
Unknown Object (File)
Wed, Jun 17, 12:51 AM

Details

Summary
Even though it is not dereferenced, it is UB to take the address of an
out of bounds array element.

Diff Detail

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

Event Timeline

bz added a subscriber: bz.
bz added inline comments.
sys/netlink/netlink_generic.c
118

I do not like initialization during declaration, especially if there is an early return before they are used (I am sure compilers optimize that but it makes reading harder as you keep state in your head). But given that's common in this code ...

This revision is now accepted and ready to land.May 22 2026, 1:17 AM
sys/netlink/netlink_generic.c
131–136

And no need for initialization at the beginning.

pouria added inline comments.
sys/netlink/netlink_generic.c
131–136

+1

This revision now requires review to proceed.May 22 2026, 12:01 PM
emaste marked an inline comment as done.
This revision is now accepted and ready to land.May 22 2026, 12:06 PM
emaste updated this revision to Diff 178387.

Version that builds :)

This revision is now accepted and ready to land.May 22 2026, 2:12 PM
jrtc27 added inline comments.
sys/netlink/netlink_generic.c
131–137

is how you'd write it to avoid code duplication if you really cared about that sort of thing, for what it's worth, but I'm not convinced the obfuscation is worth it, it's not a complicated expression to duplicate. Also the same pattern is present below for cmd (though it and ghdr are not declared at the block's start like they should be...).

adrian added a subscriber: adrian.

sure, but yes, short-circuit evaluation in C is fine!

This revision was automatically updated to reflect the committed changes.