From 48e75dc5e6cab5b1a48f3806ad81dc133c1544eb Mon Sep 17 00:00:00 2001 From: Irfan Mohammad Date: Mon, 10 Feb 2025 08:33:23 +0000 Subject: [PATCH] use strnlen instead of strlen to check valid time Using strlen() on large strings (large imported data) is extremely inefficient. The ly_time_str2time() only needs to check that the string is at least as long as a valid time value. However, the full value string can be very long (even > 10MB), and evaluating strlen() for every time value results in poor performance. --- src/tree_data_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tree_data_common.c b/src/tree_data_common.c index ce9479d82..e9b0653df 100644 --- a/src/tree_data_common.c +++ b/src/tree_data_common.c @@ -1670,7 +1670,7 @@ ly_time_str2time(const char *value, time_t *time, char **fractions_s) int64_t shift, shift_m; time_t t; - LY_CHECK_ARG_RET(NULL, value, strlen(value) > 17, time, LY_EINVAL); + LY_CHECK_ARG_RET(NULL, value, strnlen(value, 18) > 17, time, LY_EINVAL); tm.tm_year = atoi(&value[0]) - 1900; tm.tm_mon = atoi(&value[5]) - 1;