NetBSD Problem Report #18170

Received: (qmail 20830 invoked by uid 605); 4 Sep 2002 20:12:59 -0000
Message-Id: <>
Date: Wed,  4 Sep 2002 13:12:57 -0700 (PDT)
Subject: caltontp() function in NTP subsystem ignores "seconds" field of input argument
X-Send-Pr-Version: www-1.0

>Number:         18170
>Category:       lib
>Synopsis:       caltontp() function in NTP subsystem ignores "seconds" field of input argument
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Sep 04 20:13:00 +0000 2002
>Last-Modified:  Fri Dec 05 16:25:00 +0000 2003
>Originator:     Rob Lester
>Release:        1.5
Quantum Corporation
An embedded system which implements NTP support.
The function caltontp() is used to convert a date/time timestamp to
an NTP compliant "number of seconds since 1/1/1900" timestamp.  From
a review of the sources, it is clear that the seconds field 
"second" of the input argument "struct calendar *jt" is not used by

Note however that the function which does conversions in the other
direction - caljulian() - does create the seconds field in the output
calendar structure when necessary.

This means that if you take a calendar structure, convert it to NTP
with caltontp(), and then reverse the conversion with caljulian(),
the resulting calendar structure has a zero in the seconds field
regardless of the seconds field in the input calendar structure.
The result is that up to a 1 minute precision error can occur when
restoring a saved NTP timestamp to calendar format.

1. Instantiate a "struct calendar" variable named jt and an unsigned
   long named ntp.
2. Initialize the fields in the variable jt to anything, except that
   the field "second" must be non-zero.
3. Convert to an NTP timestamp: ntp = caltontp(&jt)
4. Convert back to calendar format: caljulian(ntp, &jt);

Now, jt.second is not the same as when you originally started.  A loss
in precision of up to 1 minute has occurred due to the ignored
seconds field when caltontp() was called.

In caltontp(), change:
 ntp_time = 
    ntp_days*SECSPERDAY+SECSPERMIN*(MINSPERHR*jt->hour + jt->minute);

To read:
 ntp_time = 
    ntp_days*SECSPERDAY+SECSPERMIN*(MINSPERHR*jt->hour + jt->minute)


From: Matthias Drochner <>
Subject: Re: lib/18170: caltontp() function in NTP subsystem ignores "seconds" 
 field of input argument
Date: Fri, 05 Dec 2003 17:24:30 +0100

 This is still in ntp-4.2.0.
 Can you report the bug to

 best regards


NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD:,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.