From 1d808a1f1cc9a12841b5bf502d0e9cabf54d6cd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Thu, 8 May 2025 19:09:18 +0200 Subject: [PATCH] core: fix buffer overflow in function util_parse_time --- CHANGELOG.md | 1 + src/core/core-util.c | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 581fc07b4..7ef097e63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ SPDX-License-Identifier: GPL-3.0-or-later - core: consider all keys are safe in cursor context ([#2244](https://github.com/weechat/weechat/issues/2244)) - core: fix integer overflow with decimal numbers in calculation of expression - core: fix integer overflow in base32 encoding/decoding +- core: fix buffer overflow in function util_parse_time - core: fix memory leak in function util_parse_delay - irc: display nick changes and quit messages when option irc.look.ignore_tag_messages is enabled ([#2241](https://github.com/weechat/weechat/issues/2241)) - perl: fix build when multiplicity is not available ([#2243](https://github.com/weechat/weechat/issues/2243)) diff --git a/src/core/core-util.c b/src/core/core-util.c index 2a3d426df..5e1f660b3 100644 --- a/src/core/core-util.c +++ b/src/core/core-util.c @@ -287,7 +287,8 @@ util_strftimeval (char *string, int max, const char *format, struct timeval *tv) int util_parse_time (const char *datetime, struct timeval *tv) { - char *string, *pos, *pos2, str_usec[16], *error, str_date[128]; + char *string, *pos, *pos2, str_usec[16], *error; + char str_date[128], str_date2[256]; struct tm tm_date, tm_date_gm, tm_date_local, *local_time; time_t time_now, time_gm, time_local; long long value; @@ -447,10 +448,10 @@ util_parse_time (const char *datetime, struct timeval *tv) local_time = localtime (&time_now); strftime (str_date, sizeof (str_date), "%Y-%m-%dT", local_time); - strcat (str_date, string); + snprintf (str_date2, sizeof (str_date2), "%s%s", str_date, string); /* initialize structure, because strptime does not do it */ memset (&tm_date, 0, sizeof (struct tm)); - pos = strptime (str_date, "%Y-%m-%dT%H:%M:%S", &tm_date); + pos = strptime (str_date2, "%Y-%m-%dT%H:%M:%S", &tm_date); if (pos) { if (use_local_time)