Fix strftime(3) short buffer checks strftime(3) returns 0 if the buffer was too short to write the complete string (including NUL) and will never return more than maxsize-1. ok stsp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
diff --git a/got/got.c b/got/got.c
index 9bcd279..5a81fdd 100644
--- a/got/got.c
+++ b/got/got.c
@@ -4570,7 +4570,7 @@ blame_cb(void *arg, int nlines, int lineno, struct got_object_id *id)
if (localtime_r(&committer_time, &tm) == NULL)
return got_error_from_errno("localtime_r");
if (strftime(bline->datebuf, sizeof(bline->datebuf), "%G-%m-%d",
- &tm) >= sizeof(bline->datebuf)) {
+ &tm) == 0) {
err = got_error(GOT_ERR_NO_SPACE);
goto done;
}
@@ -10073,7 +10073,7 @@ print_path_info(void *arg, const char *path, mode_t mode, time_t mtime,
tm = localtime_r(&mtime, &mytm);
if (tm == NULL)
return NULL;
- if (strftime(datebuf, sizeof(datebuf), "%c %Z", tm) >= sizeof(datebuf))
+ if (strftime(datebuf, sizeof(datebuf), "%c %Z", tm) == 0)
return got_error(GOT_ERR_NO_SPACE);
printf("timestamp: %s\n", datebuf);
diff --git a/gotweb/gotweb.c b/gotweb/gotweb.c
index 5251b5a..3b1cd05 100644
--- a/gotweb/gotweb.c
+++ b/gotweb/gotweb.c
@@ -3821,7 +3821,7 @@ gw_blame_cb(void *arg, int nlines, int lineno, struct got_object_id *id)
if (localtime_r(&committer_time, &tm) == NULL)
return got_error_from_errno("localtime_r");
if (strftime(bline->datebuf, sizeof(bline->datebuf), "%G-%m-%d",
- &tm) >= sizeof(bline->datebuf)) {
+ &tm) == 0) {
err = got_error(GOT_ERR_NO_SPACE);
goto done;
}
diff --git a/tog/tog.c b/tog/tog.c
index 66c10af..c426e9d 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -1343,8 +1343,7 @@ draw_commit(struct tog_view *view, struct got_commit_object *commit,
committer_time = got_object_commit_get_committer_time(commit);
if (localtime_r(&committer_time, &tm) == NULL)
return got_error_from_errno("localtime_r");
- if (strftime(datebuf, sizeof(datebuf), "%G-%m-%d ", &tm)
- >= sizeof(datebuf))
+ if (strftime(datebuf, sizeof(datebuf), "%G-%m-%d ", &tm) == 0)
return got_error(GOT_ERR_NO_SPACE);
if (avail <= date_display_cols)