Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20038fe8-3c24-4acb-af7d-8e493df57a1d@gmail.com>
Date: Mon, 30 Nov 2026 19:51:18 +0100
From: Gabriel Ravier <gabravier@...il.com>
To: musl@...ts.openwall.com, AyadiCH <ayadich@...ton.me>
Subject: Re: getdate() returns invalid date

On 11/27/26 3:39 PM, AyadiCH wrote:
> this should fix it, it get out from Bruno's test and should
> be as specified in the posix, thanks a lot Burno!
> 
> Ayadi
> 
> ----
>  From 8e1a6138dd77718d38087e06a027b49414e1edd8 Mon Sep 17 00:00:00 2001
> From: Ayadi <ayadich@...ton.me>
> Date: Fri, 27 Nov 2026 15:33:11 +0100
> Subject: [PATCH] fixing getdate
> 
> ---
>   src/time/getdate.c | 22 ++++++++++++++++++++--
>   1 file changed, 20 insertions(+), 2 deletions(-)
> 
> diff --git a/src/time/getdate.c b/src/time/getdate.c
> index 420cd8e4..649f3c96 100644
> --- a/src/time/getdate.c
> +++ b/src/time/getdate.c
> @@ -14,7 +14,9 @@ struct tm *getdate(const char *s)
>   	FILE *f = 0;
>   	char fmt[100], *p;
>   	int cs;
> -
> +	time_t rtm;
> +	int ptm_hour, ptm_min, ptm_sec;
> +	
>   	pthread_setcancelstate(PTHREAD_CANCEL_DEFERRED, &cs);
>   
>   	if (!datemsk) {
> @@ -29,9 +31,25 @@ struct tm *getdate(const char *s)
>   		goto out;
>   	}
>   
> +	time(&rtm);
>   	while (fgets(fmt, sizeof fmt, f)) {
> -		p = strptime(s, fmt, &tmbuf);
> +		localtime_r(&rtm,&tmbuf);
> +		ptm_hour=tmbuf.tm_hour;ptm_min=tmbuf.tm_min;ptm_sec=tmbuf.tm_sec;
> +		tmbuf.tm_min = tmbuf.tm_sec =tmbuf.tm_hour= -1;
> +		p = strptime(s, fmt, &tmbuf);	
> +		
>   		if (p && !*p) {
> +			if(tmbuf.tm_hour == -1){
> +				tmbuf.tm_hour = ptm_hour;
> +				tmbuf.tm_min  = ptm_min;
> +				tmbuf.tm_sec  = ptm_sec;
> +			}
> +			if(tmbuf.tm_min == -1){
> +				tmbuf.tm_min = 0;
> +			}
> +			if(tmbuf.tm_sec == -1){
> +				tmbuf.tm_sec = 0;
> +			}
>   			ret = &tmbuf;
>   			goto out;
>   		}

I've tested this patch on @1795994640 (Sunday 23:24 UTC) and it fails in 
several ways that I believe do not match POSIX:
- 13:30 -> 2026-11-29 13:30 (POSIX requires Nov 30)
- March -> 2026-03-29 23:24, yday=333 (POSIX requires 2027-03-01, 1st of
   next March)
- Monday -> 2026-11-29 with wday=1 (Posix requires Nov 30)
- Friday -> 2026-11-29 with wday=5 (Posix requires Dec 4)

...Bruno's test only passes if run before 13:30, too.

Also as an aside (unrelated issues aiui), while comparing POSIX and musl 
I noticed that:
- DATEMSK=/dev/null should return 4 instead of 7, as musl currently does
- DATEMSK=/tmp should return 4 instead of 5, as musl currently does
- A FIFO blocks entirely
- The call to pthread_setcancelstate(PTHREAD_CANCEL_DEFERRED
   accidentally enables cancellation, because it incorrectly passes a
   type instead of a state which ends up being treated as ENABLE.

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.