Skip to content

Commit

Permalink
Fix iteration after expiring a list entry
Browse files Browse the repository at this point in the history
After removing an entry, the next entry will be at the same offset as
the entry we just removed.  Also the total length will have changed.

Update the length when we remove an entry, and advance the offset only
when we don't.

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
  • Loading branch information
bwhacks committed Jan 28, 2016
1 parent 6326ab3 commit d277ddb
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/odhcp6c.c
Expand Up @@ -619,7 +619,7 @@ static void odhcp6c_expire_list(enum odhcp6c_state state, uint32_t elapsed)
uint8_t *start = odhcp6c_get_state(state, &len);
for (struct odhcp6c_entry *c = (struct odhcp6c_entry*)start;
(uint8_t*)c < &start[len] && &c->auxtarget[c->auxlen] <= &start[len];
c = (struct odhcp6c_entry*)(&c->auxtarget[c->auxlen])) {
) {
if (c->t1 < elapsed)
c->t1 = 0;
else if (c->t1 != UINT32_MAX)
Expand All @@ -640,8 +640,12 @@ static void odhcp6c_expire_list(enum odhcp6c_state state, uint32_t elapsed)
else if (c->valid != UINT32_MAX)
c->valid -= elapsed;

if (!c->valid)
if (!c->valid) {
odhcp6c_remove_state(state, ((uint8_t*)c) - start, sizeof(*c) + c->auxlen);
start = odhcp6c_get_state(state, &len);
} else {
c = (struct odhcp6c_entry*)(&c->auxtarget[c->auxlen]);
}
}
}

Expand Down

0 comments on commit d277ddb

Please sign in to comment.