diff --git a/src/core/core-util.c b/src/core/core-util.c index 249e02297..b3db6e301 100644 --- a/src/core/core-util.c +++ b/src/core/core-util.c @@ -417,7 +417,7 @@ int util_parse_time (const char *datetime, struct timeval *tv) { char *string, *pos, *pos2, *pos_colon, *pos_hyphen, *pos_dot; - char str_usec[16], *error, str_date[128], str_date2[256]; + char str_usec[16], *error, str_date[128]; struct tm tm_date, tm_date_gm, tm_date_local, *local_time; time_t time_now, time_gm, time_local; long long value; @@ -441,21 +441,23 @@ util_parse_time (const char *datetime, struct timeval *tv) if (pos_colon && !pos_hyphen) { /* add current date: "19:04:55" -> "2025-08-30T19:04:55" */ - string = malloc (strlen (datetime) + 16 + 1); - if (!string) - return 0; time_now = time (NULL); local_time = localtime (&time_now); strftime (str_date, sizeof (str_date), "%Y-%m-%dT", local_time); - snprintf (string, sizeof (str_date2), "%s%s", str_date, datetime); + length = strlen (str_date) + strlen (datetime) + 1; + string = malloc (length); + if (!string) + return 0; + snprintf (string, length, "%s%s", str_date, datetime); } else if (!pos_colon && pos_hyphen && (!pos_dot || (pos_hyphen < pos_dot))) { /* add time (midnight): "2025-08-30" -> "2025-08-30T00:00:00" */ - string = malloc (strlen (datetime) + 16 + 1); + length = strlen (datetime) + 9 + 1; + string = malloc (length); if (!string) return 0; - snprintf (string, sizeof (str_date2), "%sT00:00:00", datetime); + snprintf (string, length, "%sT00:00:00", datetime); } else {