]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bfdd: Fix overflow possibility with time statements
authorDonald Sharp <sharpd@nvidia.com>
Fri, 18 Feb 2022 15:45:46 +0000 (10:45 -0500)
committerDonald Sharp <sharpd@nvidia.com>
Tue, 22 Feb 2022 16:11:31 +0000 (11:11 -0500)
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>
bfdd/bfd.c

index fbe0436b508133c03770f62983f6f43fae89982b..588c9fc00faa1b5c36669a3315e28e3dfbf093fa 100644 (file)
@@ -1424,7 +1424,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)
@@ -1436,7 +1436,7 @@ 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;
        }
@@ -1444,7 +1444,7 @@ void integer2timestr(uint64_t time, char *buf, size_t buflen)
                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;
        }
@@ -1452,7 +1452,7 @@ void integer2timestr(uint64_t time, char *buf, size_t buflen)
                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;
        }
@@ -1460,7 +1460,7 @@ void integer2timestr(uint64_t time, char *buf, size_t buflen)
                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;
        }
@@ -1468,12 +1468,12 @@ void integer2timestr(uint64_t time, char *buf, size_t buflen)
                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)