Re: git rev-parse --since=1970-01-01 does not work reliably

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2011/11/1 Nguyen Thai Ngoc Duy <pclouds@xxxxxxxxx>:
> Subject: [PATCH] Do not accept negative time_t
>
> We use unsigned long internally to present time, negative value just
> breaks thing.

Junio, what do you think about this patch?

> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx>
> ---
>  date.c |    8 +++++++-
>  1 files changed, 7 insertions(+), 1 deletions(-)
>
> diff --git a/date.c b/date.c
> index 353e0a5..9cbd521 100644
> --- a/date.c
> +++ b/date.c
> @@ -653,8 +653,12 @@ int parse_date_basic(const char *date, unsigned long *timestamp, int *offset)
>        if (*timestamp == -1)
>                return -1;
>
> -       if (!tm_gmt)
> +       if (!tm_gmt) {
> +               if ((time_t)*timestamp < (time_t)*offset * 60)
> +                       die("unsupported time before Epoch");
>                *timestamp -= *offset * 60;
> +       }
> +
>        return 0; /* success */
>  }
>
> @@ -722,6 +726,8 @@ static unsigned long update_tm(struct tm *tm, struct tm *now, unsigned long sec)
>
>        n = mktime(tm) - sec;
>        localtime_r(&n, tm);
> +       if (n < 0)
> +               die("unsupported time before Epoch");
>        return n;
>  }
>
> --
> 1.7.4.74.g639db
> -- 8< --
>



-- 
Duy
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]