From 7328c4de54ac96b39853b3f43736aff863fd209d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 29 Nov 2022 11:18:15 +0800 Subject: vim-patch:9.0.0733: use of strftime() is not safe (#21228) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Use of strftime() is not safe. Solution: Check the return value of strftime(). Use a larger buffer and correctly pass the available space. (Dominique Pellé, closes vim/vim#11348) https://github.com/vim/vim/commit/84d14ccdb50dc9f362066a2c83bfaf331314e5ea Co-authored-by: Dominique Pelle --- src/nvim/undo.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/nvim/undo.c') diff --git a/src/nvim/undo.c b/src/nvim/undo.c index 0b86a82619..05adc3c6d3 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -2600,12 +2600,16 @@ void undo_fmt_time(char_u *buf, size_t buflen, time_t tt) if (time(NULL) - tt >= 100) { struct tm curtime; os_localtime_r(&tt, &curtime); + size_t n; if (time(NULL) - tt < (60L * 60L * 12L)) { // within 12 hours - (void)strftime((char *)buf, buflen, "%H:%M:%S", &curtime); + n = strftime((char *)buf, buflen, "%H:%M:%S", &curtime); } else { // longer ago - (void)strftime((char *)buf, buflen, "%Y/%m/%d %H:%M:%S", &curtime); + n = strftime((char *)buf, buflen, "%Y/%m/%d %H:%M:%S", &curtime); + } + if (n == 0) { + buf[0] = NUL; } } else { int64_t seconds = time(NULL) - tt; -- cgit