logo

oasis

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

0002-Avoid-pointer-arithmetic-on-void.patch (8174B)


  1. From a5c387d23c3309296d852e6f7fae8eb6ca99bd47 Mon Sep 17 00:00:00 2001
  2. From: Michael Forney <mforney@mforney.org>
  3. Date: Tue, 12 Mar 2019 19:12:31 -0700
  4. Subject: [PATCH] Avoid pointer arithmetic on `void *`
  5. ---
  6. include/libnetlink.h | 4 ++--
  7. ip/ipfou.c | 2 +-
  8. ip/ipila.c | 2 +-
  9. ip/ipioam6.c | 3 ++-
  10. ip/ipl2tp.c | 2 +-
  11. ip/ipmacsec.c | 2 +-
  12. ip/ipmptcp.c | 6 +++---
  13. ip/ipseg6.c | 2 +-
  14. ip/tcp_metrics.c | 2 +-
  15. lib/libnetlink.c | 12 ++++++------
  16. lib/utils.c | 2 +-
  17. 11 files changed, 20 insertions(+), 19 deletions(-)
  18. diff --git a/include/libnetlink.h b/include/libnetlink.h
  19. index ad7e7127..09145d77 100644
  20. --- a/include/libnetlink.h
  21. +++ b/include/libnetlink.h
  22. @@ -219,7 +219,7 @@ struct rtattr *rta_nest(struct rtattr *rta, int maxlen, int type);
  23. int rta_nest_end(struct rtattr *rta, struct rtattr *nest);
  24. #define RTA_TAIL(rta) \
  25. - ((struct rtattr *) (((void *) (rta)) + \
  26. + ((struct rtattr *) (((char *) (rta)) + \
  27. RTA_ALIGN((rta)->rta_len)))
  28. #define parse_rtattr_nested(tb, max, rta) \
  29. @@ -287,7 +287,7 @@ int rtnl_from_file(FILE *, rtnl_listen_filter_t handler,
  30. void *jarg);
  31. #define NLMSG_TAIL(nmsg) \
  32. - ((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len)))
  33. + ((struct rtattr *) (((char *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len)))
  34. #ifndef IFA_RTA
  35. #define IFA_RTA(r) \
  36. diff --git a/ip/ipfou.c b/ip/ipfou.c
  37. index 760cfee2..8b9dde00 100644
  38. --- a/ip/ipfou.c
  39. +++ b/ip/ipfou.c
  40. @@ -228,7 +228,7 @@ static int print_fou_mapping(struct nlmsghdr *n, void *arg)
  41. return -1;
  42. ghdr = NLMSG_DATA(n);
  43. - parse_rtattr(tb, FOU_ATTR_MAX, (void *) ghdr + GENL_HDRLEN, len);
  44. + parse_rtattr(tb, FOU_ATTR_MAX, (struct rtattr *)((char *)ghdr + GENL_HDRLEN), len);
  45. open_json_object(NULL);
  46. if (tb[FOU_ATTR_PORT])
  47. diff --git a/ip/ipila.c b/ip/ipila.c
  48. index f4387e03..c12aa23f 100644
  49. --- a/ip/ipila.c
  50. +++ b/ip/ipila.c
  51. @@ -97,7 +97,7 @@ static int print_ila_mapping(struct nlmsghdr *n, void *arg)
  52. return -1;
  53. ghdr = NLMSG_DATA(n);
  54. - parse_rtattr(tb, ILA_ATTR_MAX, (void *) ghdr + GENL_HDRLEN, len);
  55. + parse_rtattr(tb, ILA_ATTR_MAX, (struct rtattr *)((char *)ghdr + GENL_HDRLEN), len);
  56. open_json_object(NULL);
  57. print_ila_locid("locator_match", ILA_ATTR_LOCATOR_MATCH, tb);
  58. diff --git a/ip/ipioam6.c b/ip/ipioam6.c
  59. index b63d7d5c..c7c9aceb 100644
  60. --- a/ip/ipioam6.c
  61. +++ b/ip/ipioam6.c
  62. @@ -110,7 +110,8 @@ static int process_msg(struct nlmsghdr *n, void *arg)
  63. return -1;
  64. ghdr = NLMSG_DATA(n);
  65. - parse_rtattr(attrs, IOAM6_ATTR_MAX, (void *)ghdr + GENL_HDRLEN, len);
  66. + parse_rtattr(attrs, IOAM6_ATTR_MAX,
  67. + (struct rtattr *)((char *)ghdr + GENL_HDRLEN), len);
  68. open_json_object(NULL);
  69. switch (ghdr->cmd) {
  70. diff --git a/ip/ipl2tp.c b/ip/ipl2tp.c
  71. index 9d1e566c..76ba20c0 100644
  72. --- a/ip/ipl2tp.c
  73. +++ b/ip/ipl2tp.c
  74. @@ -341,7 +341,7 @@ static int get_response(struct nlmsghdr *n, void *arg)
  75. if (len < 0)
  76. return -1;
  77. - parse_rtattr(attrs, L2TP_ATTR_MAX, (void *)ghdr + GENL_HDRLEN, len);
  78. + parse_rtattr(attrs, L2TP_ATTR_MAX, (struct rtattr *)((char *)ghdr + GENL_HDRLEN), len);
  79. if (attrs[L2TP_ATTR_PW_TYPE])
  80. p->pw_type = rta_getattr_u16(attrs[L2TP_ATTR_PW_TYPE]);
  81. diff --git a/ip/ipmacsec.c b/ip/ipmacsec.c
  82. index fc4c8631..3e65e11f 100644
  83. --- a/ip/ipmacsec.c
  84. +++ b/ip/ipmacsec.c
  85. @@ -1083,7 +1083,7 @@ static int process(struct nlmsghdr *n, void *arg)
  86. if (ghdr->cmd != MACSEC_CMD_GET_TXSC)
  87. return 0;
  88. - parse_rtattr(attrs, MACSEC_ATTR_MAX, (void *) ghdr + GENL_HDRLEN, len);
  89. + parse_rtattr(attrs, MACSEC_ATTR_MAX, (struct rtattr *)((char *)ghdr + GENL_HDRLEN), len);
  90. if (!validate_dump(attrs)) {
  91. fprintf(stderr, "incomplete dump message\n");
  92. return -1;
  93. diff --git a/ip/ipmptcp.c b/ip/ipmptcp.c
  94. index 9847f95b..d37f1269 100644
  95. --- a/ip/ipmptcp.c
  96. +++ b/ip/ipmptcp.c
  97. @@ -286,7 +286,7 @@ static int print_mptcp_addr(struct nlmsghdr *n, void *arg)
  98. return -1;
  99. ghdr = NLMSG_DATA(n);
  100. - parse_rtattr_flags(tb, MPTCP_PM_ATTR_MAX, (void *) ghdr + GENL_HDRLEN,
  101. + parse_rtattr_flags(tb, MPTCP_PM_ATTR_MAX, (struct rtattr *)((char *)ghdr + GENL_HDRLEN),
  102. len, NLA_F_NESTED);
  103. addrinfo = tb[MPTCP_PM_ATTR_ADDR];
  104. if (!addrinfo)
  105. @@ -402,7 +402,7 @@ static int print_mptcp_limit(struct nlmsghdr *n, void *arg)
  106. return -1;
  107. ghdr = NLMSG_DATA(n);
  108. - parse_rtattr(tb, MPTCP_PM_ATTR_MAX, (void *) ghdr + GENL_HDRLEN, len);
  109. + parse_rtattr(tb, MPTCP_PM_ATTR_MAX, (struct rtattr *)((char *)ghdr + GENL_HDRLEN), len);
  110. open_json_object(NULL);
  111. if (tb[MPTCP_PM_ATTR_RCV_ADD_ADDRS]) {
  112. @@ -497,7 +497,7 @@ static int mptcp_monitor_msg(struct rtnl_ctrl_data *ctrl,
  113. printf("[%16s]", event_to_str[ghdr->cmd]);
  114. - parse_rtattr(tb, MPTCP_ATTR_MAX, (void *) ghdr + GENL_HDRLEN, len);
  115. + parse_rtattr(tb, MPTCP_ATTR_MAX, (struct rtattr *) ((char *) ghdr + GENL_HDRLEN), len);
  116. if (tb[MPTCP_ATTR_TOKEN])
  117. printf(" token=%08x", rta_getattr_u32(tb[MPTCP_ATTR_TOKEN]));
  118. diff --git a/ip/ipseg6.c b/ip/ipseg6.c
  119. index 305b8961..4103a1c6 100644
  120. --- a/ip/ipseg6.c
  121. +++ b/ip/ipseg6.c
  122. @@ -112,7 +112,7 @@ static int process_msg(struct nlmsghdr *n, void *arg)
  123. ghdr = NLMSG_DATA(n);
  124. - parse_rtattr(attrs, SEG6_ATTR_MAX, (void *)ghdr + GENL_HDRLEN, len);
  125. + parse_rtattr(attrs, SEG6_ATTR_MAX, (struct rtattr *)((char *)ghdr + GENL_HDRLEN), len);
  126. open_json_object(NULL);
  127. switch (ghdr->cmd) {
  128. diff --git a/ip/tcp_metrics.c b/ip/tcp_metrics.c
  129. index 9c8fb072..f451c8f2 100644
  130. --- a/ip/tcp_metrics.c
  131. +++ b/ip/tcp_metrics.c
  132. @@ -175,7 +175,7 @@ static int process_msg(struct nlmsghdr *n, void *arg)
  133. if (ghdr->cmd != TCP_METRICS_CMD_GET)
  134. return 0;
  135. - parse_rtattr(attrs, TCP_METRICS_ATTR_MAX, (void *) ghdr + GENL_HDRLEN,
  136. + parse_rtattr(attrs, TCP_METRICS_ATTR_MAX, (struct rtattr *)((char *)ghdr + GENL_HDRLEN),
  137. len);
  138. if (attrs[TCP_METRICS_ATTR_ADDR_IPV4]) {
  139. diff --git a/lib/libnetlink.c b/lib/libnetlink.c
  140. index 01648229..80adabf4 100644
  141. --- a/lib/libnetlink.c
  142. +++ b/lib/libnetlink.c
  143. @@ -1396,7 +1396,7 @@ int addraw_l(struct nlmsghdr *n, int maxlen, const void *data, int len)
  144. }
  145. memcpy(NLMSG_TAIL(n), data, len);
  146. - memset((void *) NLMSG_TAIL(n) + len, 0, NLMSG_ALIGN(len) - len);
  147. + memset((char *) NLMSG_TAIL(n) + len, 0, NLMSG_ALIGN(len) - len);
  148. n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + NLMSG_ALIGN(len);
  149. return 0;
  150. }
  151. @@ -1411,7 +1411,7 @@ struct rtattr *addattr_nest(struct nlmsghdr *n, int maxlen, int type)
  152. int addattr_nest_end(struct nlmsghdr *n, struct rtattr *nest)
  153. {
  154. - nest->rta_len = (void *)NLMSG_TAIL(n) - (void *)nest;
  155. + nest->rta_len = (char *)NLMSG_TAIL(n) - (char *)nest;
  156. return n->nlmsg_len;
  157. }
  158. @@ -1427,9 +1427,9 @@ struct rtattr *addattr_nest_compat(struct nlmsghdr *n, int maxlen, int type,
  159. int addattr_nest_compat_end(struct nlmsghdr *n, struct rtattr *start)
  160. {
  161. - struct rtattr *nest = (void *)start + NLMSG_ALIGN(start->rta_len);
  162. + struct rtattr *nest = (struct rtattr *)((char *)start + NLMSG_ALIGN(start->rta_len));
  163. - start->rta_len = (void *)NLMSG_TAIL(n) - (void *)start;
  164. + start->rta_len = (char *)NLMSG_TAIL(n) - (char *)start;
  165. addattr_nest_end(n, nest);
  166. return n->nlmsg_len;
  167. }
  168. @@ -1501,7 +1501,7 @@ struct rtattr *rta_nest(struct rtattr *rta, int maxlen, int type)
  169. int rta_nest_end(struct rtattr *rta, struct rtattr *nest)
  170. {
  171. - nest->rta_len = (void *)RTA_TAIL(rta) - (void *)nest;
  172. + nest->rta_len = (char *)RTA_TAIL(rta) - (char *)nest;
  173. return rta->rta_len;
  174. }
  175. @@ -1550,7 +1550,7 @@ int __parse_rtattr_nested_compat(struct rtattr *tb[], int max,
  176. if (RTA_PAYLOAD(rta) < len)
  177. return -1;
  178. if (RTA_PAYLOAD(rta) >= RTA_ALIGN(len) + sizeof(struct rtattr)) {
  179. - rta = RTA_DATA(rta) + RTA_ALIGN(len);
  180. + rta = (struct rtattr *)((char *)RTA_DATA(rta) + RTA_ALIGN(len));
  181. return parse_rtattr_nested(tb, max, rta);
  182. }
  183. memset(tb, 0, sizeof(struct rtattr *) * (max + 1));
  184. diff --git a/lib/utils.c b/lib/utils.c
  185. index 6c1c1a8d..040b935c 100644
  186. --- a/lib/utils.c
  187. +++ b/lib/utils.c
  188. @@ -1543,7 +1543,7 @@ int get_rtnl_link_stats_rta(struct rtnl_link_stats64 *stats64,
  189. len = RTA_PAYLOAD(rta);
  190. if (len < size)
  191. - memset(s + len, 0, size - len);
  192. + memset((char *)s + len, 0, size - len);
  193. else
  194. len = size;
  195. --
  196. 2.44.0