logo

oasis

Own branch of Oasis Linux (upstream: <https://git.sr.ht/~mcf/oasis/>) git clone https://anongit.hacktivis.me/git/oasis.git

0006-Avoid-use-of-alloca-and-statement-expressions.patch (2291B)


  1. From f64cfa931a450ffb08cbbdeb6652b424f6bb8187 Mon Sep 17 00:00:00 2001
  2. From: Michael Forney <mforney@mforney.org>
  3. Date: Thu, 30 Jan 2020 14:12:35 -0800
  4. Subject: [PATCH] Avoid use of alloca and statement expressions
  5. ---
  6. include/netlink-private/utils.h | 21 ---------------------
  7. lib/genl/mngt.c | 13 +++++++++----
  8. 2 files changed, 9 insertions(+), 25 deletions(-)
  9. diff --git a/include/netlink-private/utils.h b/include/netlink-private/utils.h
  10. index 1456797..e26399f 100644
  11. --- a/include/netlink-private/utils.h
  12. +++ b/include/netlink-private/utils.h
  13. @@ -93,27 +93,6 @@ extern const char *nl_strerror_l(int err);
  14. /*****************************************************************************/
  15. -#define _nl_malloc_maybe_a(alloca_maxlen, bytes, to_free) \
  16. - ({ \
  17. - const size_t _bytes = (bytes); \
  18. - __typeof__ (to_free) _to_free = (to_free); \
  19. - __typeof__ (*_to_free) _ptr; \
  20. - \
  21. - _NL_STATIC_ASSERT ((alloca_maxlen) <= 500); \
  22. - _nl_assert (_to_free && !*_to_free); \
  23. - \
  24. - if (_bytes <= (alloca_maxlen)) { \
  25. - _ptr = alloca (_bytes); \
  26. - } else { \
  27. - _ptr = malloc (_bytes); \
  28. - *_to_free = _ptr; \
  29. - }; \
  30. - \
  31. - _ptr; \
  32. - })
  33. -
  34. -/*****************************************************************************/
  35. -
  36. static inline char *
  37. _nl_strncpy_trunc(char *dst, const char *src, size_t len)
  38. {
  39. diff --git a/lib/genl/mngt.c b/lib/genl/mngt.c
  40. index ff50e1d..8f92122 100644
  41. --- a/lib/genl/mngt.c
  42. +++ b/lib/genl/mngt.c
  43. @@ -54,7 +54,7 @@ static int cmd_msg_parser(struct sockaddr_nl *who, struct nlmsghdr *nlh,
  44. int err;
  45. struct genlmsghdr *ghdr;
  46. struct genl_cmd *cmd;
  47. - struct nlattr **tb;
  48. + struct nlattr **tb, *tb_local[32];
  49. ghdr = genlmsg_hdr(nlh);
  50. @@ -64,9 +64,14 @@ static int cmd_msg_parser(struct sockaddr_nl *who, struct nlmsghdr *nlh,
  51. if (cmd->c_msg_parser == NULL)
  52. return -NLE_OPNOTSUPP;
  53. - tb = _nl_malloc_maybe_a (300, (((size_t) cmd->c_maxattr) + 1u) * sizeof (struct nlattr *), &tb_free);
  54. - if (!tb)
  55. - return -NLE_NOMEM;
  56. + if (cmd->c_maxattr > ARRAY_SIZE(tb_local) - 1) {
  57. + tb = malloc(((size_t) cmd->c_maxattr + 1u) * sizeof (struct nlattr *));
  58. + if (!tb)
  59. + return -NLE_NOMEM;
  60. + tb_free = tb;
  61. + } else {
  62. + tb = tb_local;
  63. + }
  64. err = nlmsg_parse(nlh,
  65. GENL_HDRSIZE(ops->o_hdrsize),
  66. --
  67. 2.25.0