summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Hopps <chopps@labn.net>2023-06-06 15:12:58 -0400
committerChristian Hopps <chopps@labn.net>2023-06-06 15:12:58 -0400
commit565139a6d5c2541e7b740a4a972dd7c18a87a984 (patch)
tree76a34309233042358d30328e2a42ebc7c159709e
parentda877b5cedcb1380f811124788d35242381f91a0 (diff)
mgmtd: assert an assertion for coverity
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>
-rw-r--r--mgmtd/mgmt_history.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/mgmtd/mgmt_history.h b/mgmtd/mgmt_history.h
index d3f7958952..5d9b662694 100644
--- a/mgmtd/mgmt_history.h
+++ b/mgmtd/mgmt_history.h
@@ -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);
}