NetBSD-Bugs archive

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

lib/49727: parsedate(3) inappropriately processes timezone



>Number:         49727
>Category:       lib
>Synopsis:       parsedate(3) inappropriately processes timezone
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Mar 06 12:50:00 +0000 2015
>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



Home | Main Index | Thread Index | Old Index