summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2023-07-26 14:17:18 (GMT)
committerThomas Haller <thaller@redhat.com>2023-07-26 14:23:45 (GMT)
commit6af26981e727149e2e3fdfac85e2ef86b3828b11 (patch)
tree3ade84a3e843c9f6f61e414d4419992e7bf7651e
parente966209178fe73297fc3461f903d6622b5d1417a (diff)
downloadlibnl-6af26981e727149e2e3fdfac85e2ef86b3828b11.zip
libnl-6af26981e727149e2e3fdfac85e2ef86b3828b11.tar.gz
libnl-6af26981e727149e2e3fdfac85e2ef86b3828b11.tar.bz2
lib: accept NULL argument in nla_nest_cancel() for robustness
Previously, a NULL argument would most likely also do thing, but it also hits undefined behavior.
-rw-r--r--lib/attr.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/attr.c b/lib/attr.c
index 1363afb..a8913d3 100644
--- a/lib/attr.c
+++ b/lib/attr.c
@@ -991,6 +991,15 @@ void nla_nest_cancel(struct nl_msg *msg, const struct nlattr *attr)
{
ssize_t len;
+ if (!attr) {
+ /* For robustness, allow a NULL attr to do nothing. NULL is also
+ * what nla_nest_start() when out of buffer space.
+ *
+ * Warning, before libnl-3.8, the function did not accept NULL!
+ * If you care, catch NULL yourself. */
+ return;
+ }
+
len = (char *) nlmsg_tail(msg->nm_nlh) - (char *) attr;
if (len < 0)
BUG();