Skip to content

Commit a7f9a6f

Browse files
alexaringdavem330
authored andcommitted
ipv6: rpl: fix loop iteration
This patch fix the loop iteration by not walking over the last iteration. The cmpri compressing value exempt the last segment. As the code shows the last iteration will be overwritten by cmpre value handling which is for the last segment. I think this doesn't end in any bufferoverflows because we work on worst case temporary buffer sizes but it ends in not best compression settings in some cases. Fixes: 8610c7c ("net: ipv6: add support for rpl sr exthdr") Signed-off-by: Alexander Aring <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent bee3489 commit a7f9a6f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

net/ipv6/rpl.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void ipv6_rpl_srh_decompress(struct ipv6_rpl_sr_hdr *outhdr,
4848
outhdr->cmpri = 0;
4949
outhdr->cmpre = 0;
5050

51-
for (i = 0; i <= n; i++)
51+
for (i = 0; i < n; i++)
5252
ipv6_rpl_addr_decompress(&outhdr->rpl_segaddr[i], daddr,
5353
ipv6_rpl_segdata_pos(inhdr, i),
5454
inhdr->cmpri);
@@ -66,7 +66,7 @@ static unsigned char ipv6_rpl_srh_calc_cmpri(const struct ipv6_rpl_sr_hdr *inhdr
6666
int i;
6767

6868
for (plen = 0; plen < sizeof(*daddr); plen++) {
69-
for (i = 0; i <= n; i++) {
69+
for (i = 0; i < n; i++) {
7070
if (daddr->s6_addr[plen] !=
7171
inhdr->rpl_segaddr[i].s6_addr[plen])
7272
return plen;
@@ -114,7 +114,7 @@ void ipv6_rpl_srh_compress(struct ipv6_rpl_sr_hdr *outhdr,
114114
outhdr->cmpri = cmpri;
115115
outhdr->cmpre = cmpre;
116116

117-
for (i = 0; i <= n; i++)
117+
for (i = 0; i < n; i++)
118118
ipv6_rpl_addr_compress(ipv6_rpl_segdata_pos(outhdr, i),
119119
&inhdr->rpl_segaddr[i], cmpri);
120120

0 commit comments

Comments
 (0)