NetBSD Problem Report #49727

From www@NetBSD.org  Fri Mar  6 12:49:26 2015
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 3039AA6562
	for <gnats-bugs@gnats.NetBSD.org>; Fri,  6 Mar 2015 12:49:26 +0000 (UTC)
Message-Id: <20150306124925.09AA8A6567@mollari.NetBSD.org>
Date: Fri,  6 Mar 2015 12:49:25 +0000 (UTC)
From: nis7999@gmail.com
Reply-To: nis7999@gmail.com
To: gnats-bugs@NetBSD.org
Subject: parsedate(3) inappropriately processes timezone
X-Send-Pr-Version: www-1.0

>Number:         49727
>Category:       lib
>Synopsis:       parsedate(3) inappropriately processes timezone
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    lib-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Mar 06 12:50:00 +0000 2015
>Closed-Date:    Tue Jan 31 22:37:47 +0000 2023
>Last-Modified:  Tue Jan 31 22:37:47 +0000 2023
>Originator:     Shingo Nishioka
>Release:        NetBSD 6.1_STABLE (GENERIC) #1: Tue Feb 24 22:24:04 JST 2015
>Organization:
>Environment:
NetBSD miranda 6.1_STABLE NetBSD 6.1_STABLE (GENERIC) #1: Tue Feb 24 22:24:04 JST 2015  nis@miranda:/dsk/sd0/build/amd64/obj/sys/arch/amd64/compile/GENERIC amd64

>Description:
parsedate(3) inappropriately processes given timezone in two way
1. add/subtract logic is wrong: the timezone indicates how much the represented value gain relative to UTC, so while parsing localtime, timezone value should be "subtracted" from parsed time to make UTC. parsedate(3) adds it.
2. the parsed timezone unit is in minutes. so, before subtracting timezone value, it should be multiplied by 60.

>How-To-Repeat:
#include <sys/types.h>

#include <stdio.h>
#include <util.h>

int
main()
{
        int ch;
        time_t tval;
        char const *ts = "1970-01-01 09:00:00 +0900";
        tval = parsedate(ts, NULL, NULL);
        printf("parsedate(\"%s\") => %ld (should be zero)\n", ts, tval);
        return 0;
}

or

#! /bin/sh

tu="1970-01-01 00:00:00 +0000"  # the Epoch (is zero)
ts="1970-01-01 09:00:00 +0900"  # and the same time in another timezone

echo "date -d \"$ts\" => $(TZ=DONTCARE /bin/date -d "$ts" +%s) (should be zero)"
echo "date -d \"$ts\" => \"$(TZ=UTC /bin/date -d "$ts" "+%F %T %z")\" (should be
 \"$tu\")"

>Fix:
fix src/lib/libutil/parsedate.y

>Release-Note:

>Audit-Trail:

State-Changed-From-To: open->feedback
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Mon, 10 Oct 2016 01:32:37 +0000
State-Changed-Why:
I believe this has been fixed; can you check?


State-Changed-From-To: feedback->closed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Tue, 31 Jan 2023 22:37:47 +0000
State-Changed-Why:
yes, fixed (long ago now)


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2023 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.