mirror of
https://github.com/freebsd/freebsd-src.git
synced 2026-10-28 11:25:21 +01:00
mfiutil: Handle truncation in mfi_next_learn_time
Only trim the trailing newline if the output from ctime() was not truncated. To simplify the code, use strlcpy() instead of snprintf() since strlcpy() can't fail with a negative size (and the previous code probably didn't handle those errors properly given the int -> size_t conversion). Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D50882
This commit is contained in:
1 parent
fe1cd734a1
commit
10ed5b90e4
1 file changed
+2
-2
@@ -71,8 +71,8 @@ mfi_next_learn_time(uint32_t next_learn_time, char *buf, size_t sz)
|
||||
tm.tm_year = 100;
|
||||
basetime = timegm(&tm);
|
||||
basetime += (time_t)next_learn_time;
|
||||
len = snprintf(buf, sz, "%s", ctime(&basetime));
|
||||
if (len > 0)
|
||||
len = strlcpy(buf, ctime(&basetime), sz);
|
||||
if (len < sz)
|
||||
/* Get rid of the newline added by ctime(3). */
|
||||
buf[len - 1] = '\0';
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user