You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.3 KiB

  1. From c8f05589644d6b719e5a2c7fc548604f248be9be Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
  3. Date: Sun, 29 Jul 2018 17:44:06 +0200
  4. Subject: [PATCH] nl: avoid NULL pointer dereference
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. It's a valid case to call nla_put() with NULL data and 0 len. It's done e.g. in
  9. the nla_put_attr().
  10. There has to be a check for data in nla_put() as passing NULL to the memcpy()
  11. is not allowed. Even if length is 0, both pointers have to be valid.
  12. For a reference see C99 standard (7.21.1/2), it says: "pointer arguments on
  13. such a call shall still have valid values".
  14. Reported-by: Daniel Gimpelevich <daniel@gimpelevich.san-francisco.ca.us>
  15. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
  16. [christian.brauner@ubuntu.com: adapted commit message]
  17. Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  18. ---
  19. src/lxc/nl.c | 3 ++-
  20. 1 file changed, 2 insertions(+), 1 deletion(-)
  21. --- a/src/lxc/nl.c
  22. +++ b/src/lxc/nl.c
  23. @@ -61,7 +61,8 @@ static int nla_put(struct nlmsg *nlmsg,
  24. rta = NLMSG_TAIL(nlmsg->nlmsghdr);
  25. rta->rta_type = attr;
  26. rta->rta_len = rtalen;
  27. - memcpy(RTA_DATA(rta), data, len);
  28. + if (data && len)
  29. + memcpy(RTA_DATA(rta), data, len);
  30. nlmsg->nlmsghdr->nlmsg_len = tlen;
  31. return 0;
  32. }