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

Cov fun (backport #10621) #10642

Merged
merged 4 commits into from
Feb 23, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
bfdd: Fix overflow possibility with time statements
If time ( a uint64_t ) is large enough doing division
and subtraction can still lead to situations where
the resulting number is greater than a uint32_t.
Just use uint32_t as an intermediate storage spot.
This is unlikely to every occur in a time frame
I could possibly care about but makes Coverity happy.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
(cherry picked from commit 46da676)
  • Loading branch information
donaldsharp authored and mergify-bot committed Feb 23, 2022
commit b487f0aff030e7164fab973c81174909d0732733
14 changes: 7 additions & 7 deletions bfdd/bfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,7 @@ int strtosa(const char *addr, struct sockaddr_any *sa)

void integer2timestr(uint64_t time, char *buf, size_t buflen)
{
unsigned int year, month, day, hour, minute, second;
uint64_t year, month, day, hour, minute, second;
int rv;

#define MINUTES (60)
Expand All @@ -1465,44 +1465,44 @@ void integer2timestr(uint64_t time, char *buf, size_t buflen)
year = time / YEARS;
time -= year * YEARS;

rv = snprintf(buf, buflen, "%u year(s), ", year);
rv = snprintfrr(buf, buflen, "%" PRIu64 " year(s), ", year);
buf += rv;
buflen -= rv;
}
if (time >= MONTHS) {
month = time / MONTHS;
time -= month * MONTHS;

rv = snprintf(buf, buflen, "%u month(s), ", month);
rv = snprintfrr(buf, buflen, "%" PRIu64 " month(s), ", month);
buf += rv;
buflen -= rv;
}
if (time >= DAYS) {
day = time / DAYS;
time -= day * DAYS;

rv = snprintf(buf, buflen, "%u day(s), ", day);
rv = snprintfrr(buf, buflen, "%" PRIu64 " day(s), ", day);
buf += rv;
buflen -= rv;
}
if (time >= HOURS) {
hour = time / HOURS;
time -= hour * HOURS;

rv = snprintf(buf, buflen, "%u hour(s), ", hour);
rv = snprintfrr(buf, buflen, "%" PRIu64 " hour(s), ", hour);
buf += rv;
buflen -= rv;
}
if (time >= MINUTES) {
minute = time / MINUTES;
time -= minute * MINUTES;

rv = snprintf(buf, buflen, "%u minute(s), ", minute);
rv = snprintfrr(buf, buflen, "%" PRIu64 " minute(s), ", minute);
buf += rv;
buflen -= rv;
}
second = time % MINUTES;
snprintf(buf, buflen, "%u second(s)", second);
snprintfrr(buf, buflen, "%" PRIu64 " second(s)", second);
}

const char *bs_to_string(const struct bfd_session *bs)
Expand Down