Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gnrc/ipv6: Check for overflow #20771

Merged
merged 2 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions sys/net/gnrc/network_layer/ipv6/nib/_nib-router.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,14 @@ static gnrc_pktsnip_t *_offl_to_pio(_nib_offl_entry_t *offl,
uint8_t flags = 0;
uint32_t valid_ltime = (offl->valid_until == UINT32_MAX) ? UINT32_MAX :
((offl->valid_until - now) / MS_PER_SEC);
uint32_t pref_ltime = (offl->pref_until == UINT32_MAX) ? UINT32_MAX :
((offl->pref_until - now) / MS_PER_SEC);
uint32_t pref_ltime = offl->pref_until;
if (pref_ltime != UINT32_MAX) { /* reserved for infinite lifetime */
if (pref_ltime >= now) { /* avoid overflow */
pref_ltime = (pref_ltime - now) / MS_PER_SEC;
} else {
pref_ltime = 0; /* deprecated */
}
}

DEBUG("nib: Build PIO for %s/%u\n",
ipv6_addr_to_str(addr_str, &offl->pfx, sizeof(addr_str)),
Expand Down
2 changes: 1 addition & 1 deletion sys/net/gnrc/network_layer/ipv6/nib/nib_pl.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
printf(" expires %lu sec", (entry->valid_until - now) / MS_PER_SEC);
}
if (entry->pref_until < UINT32_MAX) {
printf(" deprecates %lu sec", (entry->pref_until - now) / MS_PER_SEC);
printf(" deprecates %lu sec", (now >= entry->pref_until ? 0 : entry->pref_until - now) / MS_PER_SEC);

Check warning on line 161 in sys/net/gnrc/network_layer/ipv6/nib/nib_pl.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
}
puts("");
}
Expand Down
Loading