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