include: add unlikely() notation and use it
Pablo Neira Ayuso
maintainerPATCH 1/1 include: add unlikely() notation and use it
Add this notation to highlight codepath that is unlikely to happen.
Use it a recent LLM fix that hardens mnl_attr_get_payload_len() against. malformed netlink messages, which should not happen in netlink messages coming from the kernel.
Signed-off-by Pablo Neira Ayuso <[email protected]>
--- src/attr.c | 2 +- src/internal.h | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-)
src/attr.c +1 -1
@@ -63,7 +63,7 @@ EXPORT_SYMBOL uint16_t mnl_attr_get_len(const struct nlattr *attr)*/ EXPORT_SYMBOL uint16_t mnl_attr_get_payload_len(const struct nlattr *attr) { -if (attr->nla_len <MNL_ATTR_HDRLEN ) +if (unlikely (attr->nla_len <MNL_ATTR_HDRLEN ))return 0 ;return attr->nla_len -MNL_ATTR_HDRLEN ;
src/internal.h +8 -0
@@ -8,4 +8,12 @@# define EXPORT_SYMBOL #endif +#ifdef __GNUC__ +# define likely (x) __builtin_expect(!!(x), 1) +# define unlikely (x) __builtin_expect(!!(x), 0) +#else +# define likely (x) (x) +# define unlikely (x) (x) +#endif +#endif
Signature · 1 line
2.47.3