mirror of
https://github.com/tmux/tmux.git
synced 2026-10-11 13:04:22 +00:00
Merge remote-tracking branch 'refs/remotes/tmux-openbsd/master'
* refs/remotes/tmux-openbsd/master: Do not format times that localtime_r and ctime_r cannot convert, from Alexandre Fiori. Add a maximum repeat size as well as count.
This commit is contained in:
19
format.c
19
format.c
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD: format.c,v 1.421 2026/09/28 16:52:55 nicm Exp $ */
|
/* $OpenBSD: format.c,v 1.423 2026/09/29 13:59:10 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com>
|
||||||
@@ -88,9 +88,12 @@ format_job_cmp(struct format_job *fj1, struct format_job *fj2)
|
|||||||
/* Maximum pad and trim width. */
|
/* Maximum pad and trim width. */
|
||||||
#define FORMAT_MAX_WIDTH 10000
|
#define FORMAT_MAX_WIDTH 10000
|
||||||
|
|
||||||
/* Maximum repeat size. */
|
/* Maximum repeat count. */
|
||||||
#define FORMAT_MAX_REPEAT 10000
|
#define FORMAT_MAX_REPEAT 10000
|
||||||
|
|
||||||
|
/* Maximum repeat result size in bytes. */
|
||||||
|
#define FORMAT_MAX_REPEAT_SIZE 65536
|
||||||
|
|
||||||
/* Maximum precision. */
|
/* Maximum precision. */
|
||||||
#define FORMAT_MAX_PRECISION 100
|
#define FORMAT_MAX_PRECISION 100
|
||||||
|
|
||||||
@@ -4520,8 +4523,8 @@ format_pretty_time(time_t t, int seconds)
|
|||||||
now = t;
|
now = t;
|
||||||
age = now - t;
|
age = now - t;
|
||||||
|
|
||||||
localtime_r(&now, &now_tm);
|
if (localtime_r(&now, &now_tm) == NULL || localtime_r(&t, &tm) == NULL)
|
||||||
localtime_r(&t, &tm);
|
return (xstrdup(""));
|
||||||
|
|
||||||
/* Last 24 hours. */
|
/* Last 24 hours. */
|
||||||
if (age < 24 * 3600) {
|
if (age < 24 * 3600) {
|
||||||
@@ -4692,10 +4695,12 @@ found:
|
|||||||
found = format_pretty_time(t, 0);
|
found = format_pretty_time(t, 0);
|
||||||
else {
|
else {
|
||||||
if (time_format != NULL) {
|
if (time_format != NULL) {
|
||||||
localtime_r(&t, &tm);
|
if (localtime_r(&t, &tm) == NULL)
|
||||||
|
return (NULL);
|
||||||
format_strftime(s, sizeof s, time_format, &tm);
|
format_strftime(s, sizeof s, time_format, &tm);
|
||||||
} else {
|
} else {
|
||||||
ctime_r(&t, s);
|
if (ctime_r(&t, s) == NULL)
|
||||||
|
return (NULL);
|
||||||
s[strcspn(s, "\n")] = '\0';
|
s[strcspn(s, "\n")] = '\0';
|
||||||
}
|
}
|
||||||
found = xstrdup(s);
|
found = xstrdup(s);
|
||||||
@@ -6427,7 +6432,7 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
|
|||||||
value = xstrdup("");
|
value = xstrdup("");
|
||||||
else {
|
else {
|
||||||
n = strlen(left);
|
n = strlen(left);
|
||||||
if (n != 0 && nrep > (SIZE_MAX - 1) / n) {
|
if (n != 0 && nrep > FORMAT_MAX_REPEAT_SIZE / n) {
|
||||||
format_log(es, "repeat is too long: %s", copy);
|
format_log(es, "repeat is too long: %s", copy);
|
||||||
value = xstrdup("");
|
value = xstrdup("");
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user