]> git.puffer.fish Git - matthieu/frr.git/commitdiff
mgmtd: assert an assertion for coverity
authorChristian Hopps <chopps@labn.net>
Tue, 6 Jun 2023 19:12:58 +0000 (15:12 -0400)
committerChristian Hopps <chopps@labn.net>
Tue, 6 Jun 2023 19:12:58 +0000 (15:12 -0400)
I believe coverity can't tell the length of the return value from strftime based
on the format string (like we can), so it allows `n` to be larger than it could
be which then allows `sz - n` to be negative which is size_t positive and very
large so it thinks an overrun is possible.

CID#1563211

Signed-off-by: Christian Hopps <chopps@labn.net>
mgmtd/mgmt_history.h

index d3f7958952a527f31d04924f3c48e430e2ba3115..5d9b6626949ddcb2d98651e9cfa5ea35faf2e8f0 100644 (file)
@@ -74,9 +74,11 @@ mgmt_time_to_string(struct timespec *tv, bool long_fmt, char *buffer, size_t sz)
 
        if (long_fmt) {
                n = strftime(buffer, sz, MGMT_LONG_TIME_FMT, &tm);
+               assert(n < sz);
                snprintf(&buffer[n], sz - n, ",%09lu", tv->tv_nsec);
        } else {
                n = strftime(buffer, sz, MGMT_SHORT_TIME_FMT, &tm);
+               assert(n < sz);
                snprintf(&buffer[n], sz - n, "%09lu", tv->tv_nsec);
        }