Hi Paul,

On 3/11/23 20:29, Paul Eggert wrote:
> From 1c8388d1d1831e976cdaa6e6f27bb08bf31aedc5 Mon Sep 17 00:00:00 2001
> From: Paul Eggert <egg...@cs.ucla.edu>
> Date: Sat, 11 Mar 2023 00:42:29 -0800
> Subject: [PATCH 4/6] Fix crash with large timestamps
> 
> * libmisc/date_to_str.c (date_to_str): Do not crash if gmtime
> returns NULL because the timestamp is far in the future.

Thanks :)

> Instead, use a dummy struct tm * to pacify any pedantic runtime.
> Simplify by always calling strftime, instead of sometimes strftime
> and sometimes strlcpy.
> 
> Signed-off-by: Paul Eggert <egg...@cs.ucla.edu>
> ---
>  libmisc/date_to_str.c | 15 +++++++--------
>  1 file changed, 7 insertions(+), 8 deletions(-)
> 
> diff --git a/libmisc/date_to_str.c b/libmisc/date_to_str.c
> index f3b9dc76..4b3a4f48 100644
> --- a/libmisc/date_to_str.c
> +++ b/libmisc/date_to_str.c
> @@ -35,13 +35,12 @@
>  
>  void date_to_str (size_t size, char buf[size], long date)
>  {
> -     time_t t;
> +     time_t t = date;
> +     struct tm *tm = gmtime (&t);
> +     struct tm dummy;
>  
> -     t = date;
> -     if (date < 0) {
> -             (void) strlcpy (buf, "never", size);
> -     } else {
> -             (void) strftime (buf, size, "%Y-%m-%d", gmtime (&t));
> -             buf[size - 1] = '\0';
> -     }
> +     (void) strftime (buf, size,
> +                      date < 0 ? "never" : tm ? "%Y-%m-%d" : "future",
> +                      tm ? tm : &dummy);

What's this &dummy exactly for?

Cheers,

Alex

> +     buf[size - 1] = '\0';
>  }
> -- 
> 2.37.2
> 


-- 
<http://www.alejandro-colomar.es/>
GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

_______________________________________________
Pkg-shadow-devel mailing list
Pkg-shadow-devel@alioth-lists.debian.net
https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/pkg-shadow-devel

Reply via email to