From 58545b01062e7acdaaad15f236301f3f36a6156b Mon Sep 17 00:00:00 2001 From: Alexander Feilke Date: Fri, 22 May 2026 17:39:21 +0200 Subject: cmd_date: make mk_date() static Use static as this function is not used externally. Signed-off-by: Alexander Feilke Reviewed-by: Simon Glass --- cmd/date.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'cmd/date.c') diff --git a/cmd/date.c b/cmd/date.c index d047872289c..f7ecdac7dd3 100644 --- a/cmd/date.c +++ b/cmd/date.c @@ -16,7 +16,7 @@ static const char * const weekdays[] = { "Sun", "Mon", "Tues", "Wednes", "Thurs", "Fri", "Satur", }; -int mk_date (const char *, struct rtc_time *); +static int mk_date(const char *, struct rtc_time *); static struct rtc_time default_tm = { 0, 0, 0, 1, 1, 2000, 6, 0, 0 }; @@ -117,7 +117,7 @@ static int cnvrt2 (const char *str, int *valp) * Some basic checking for valid values is done, but this will not catch * all possible error conditions. */ -int mk_date (const char *datestr, struct rtc_time *tmp) +static int mk_date(const char *datestr, struct rtc_time *tmp) { int len, val; char *ptr; -- cgit v1.3.1 From 3bf0e5d90c0c74e7dacc185558516cdf1e3b045c Mon Sep 17 00:00:00 2001 From: Markus Niebel Date: Fri, 22 May 2026 17:39:22 +0200 Subject: cmd: date: validate date using rtc_month_days() The old check accepted day 0 as well as Feb 29th in non-leap years. With this change, both day and month 0 are rejected, and the local day limit logic is now handled by rtc_month_days(), which correctly accounts for month length and leap years. In the 'MMDDhhmm' format case, tm_year is not initialized by mk_date(). The leap-year calculation in rtc_month_days() therefore depends on the value provided by the caller, which do_date() does, via dm_rtc_get(). This is pre-existing behaviour, but is now made more explicit. Signed-off-by: Markus Niebel Reviewed-by: Simon Glass Reviewed-by: Alexander Sverdlin Signed-off-by: Alexander Feilke --- cmd/date.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'cmd/date.c') diff --git a/cmd/date.c b/cmd/date.c index f7ecdac7dd3..67cfaed0d48 100644 --- a/cmd/date.c +++ b/cmd/date.c @@ -167,12 +167,13 @@ static int mk_date(const char *datestr, struct rtc_time *tmp) /* fall thru */ case 12: /* MMDDhhmmCCYY */ if (cnvrt2 (datestr+0, &val) || - val > 12) { + val > 12 || val < 1) { break; } tmp->tm_mon = val; - if (cnvrt2 (datestr+2, &val) || - val > ((tmp->tm_mon==2) ? 29 : 31)) { + if (cnvrt2(datestr + 2, &val) || + val < 1 || + val > rtc_month_days(tmp->tm_mon - 1, tmp->tm_year)) { break; } tmp->tm_mday = val; -- cgit v1.3.1