Hi Markus,
On 2026-05-08T08:21:24, Feilke, Alexander
<[email protected]> wrote:
> cmd: date: improve day of month verification
>
> Use rtc_month_days instead of oversimplified local logic.
>
> Signed-off-by: Markus Niebel <[email protected]>
>
> cmd/date.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
> diff --git a/cmd/date.c b/cmd/date.c
> @@ -167,12 +167,12 @@ 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)) {
> + val > rtc_month_days(tmp->tm_mon - 1, tmp->tm_year)) {
> break;
> }
> tmp->tm_mday = val;
Please also reject day 0 - the new check still accepts val == 0 for
tm_mday. A 'val < 1' on the day mirrors the month check.
Also worth noting in the commit message: for the len == 8 case
(MMDDhhmm) tm_year is not set in this function, so the leap-year
result from rtc_month_days() depends on whatever tm_year the caller
passed in. Pre-existing behaviour, but the new code is now sensitive
to it.
>
> Use rtc_month_days instead of oversimplified local logic.
This could use expanding. Please use rtc_month_days() with
parentheses, and mention that the old check accepted month 0 and
accepted 29 February in non-leap years, and that you also reject month
0 now.
Regards,
Simon