NetBSD-Bugs archive

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

bin/55565: mtree time= values wrong for tv_nsec<100000000



>Number:         55565
>Category:       bin
>Synopsis:       mtree time= values wrong for tv_nsec<100000000
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Aug 12 21:55:00 +0000 2020
>Originator:     Bruce Lilly
>Release:        $NetBSD: spec.c,v 1.5 2008/11/06 02:14:52 jschauma Exp $
>Organization:
>Environment:
N/A (building from source for compatibility)
>Description:
spec.c uses %ld.%ld to print tv_sec, tv_nsec fields; the fractional
part for a file with 1 nanosecond offset prints as .1
and one with 100 milliseconds offset prints as .100000000
which appear as the same thing to a human reader, and may be
interpreted as the same thing e.g. by scanf.

The issue is alluded to in the FreeBSD mtree(8) man page:
"The netbsd6 flavor does not replicate the historical bug that reported
time as seconds.nanoseconds without zero padding nanosecond values	less than 100000000."  However, the source at
ftp://ftp.netbsd.org/pub/pkgsrc/current/pkgsrc/pkgtools/mtree/files
still contains the problem format string.
>How-To-Repeat:
mtree -c -k time
compare timestamps to (e.g.)
stat -t %f
>Fix:
Source patch follows, maintainer should update the ident string;
(info:) the fractional part of the time format as modified matches
that in FreeBSD code at
https://github.com/freebsd/freebsd/blob/master/contrib/mtree/spec.c
(FreeBSD uses some oddball formats for the full seconds and some
other fields).   The man page isn't changed, but it should probably
be updated to note the format details as listed in the FreeBSD mtree(5)
and mtree(8) man pages, viz. "The value should include a period character and exactly nine digits after the period."

*** spec.c.orig 2020-08-12 15:59:52.108501015 -0400
--- spec.c      2020-08-12 17:18:17.084301702 -0400
***************
*** 1,4 ****
! /*    $NetBSD: spec.c,v 1.5 2008/11/06 02:14:52 jschauma Exp $        */
  
  /*-
   * Copyright (c) 1989, 1993
--- 1,4 ----
! /*    FIXME: $NetBSD: spec.c,v 1.5 2008/11/06 02:14:52 jschauma Exp $ */
  
  /*-
   * Copyright (c) 1989, 1993
***************
*** 385,391 ****
                if (MATCHFLAG(F_SIZE))
                        printf("size=%lld ", (long long)cur->st_size);
                if (MATCHFLAG(F_TIME))
!                       printf("time=%ld.%ld ", (long)cur->st_mtimespec.tv_sec,
                            cur->st_mtimespec.tv_nsec);
                if (MATCHFLAG(F_CKSUM))
                        printf("cksum=%lu ", cur->cksum);
--- 385,391 ----
                if (MATCHFLAG(F_SIZE))
                        printf("size=%lld ", (long long)cur->st_size);
                if (MATCHFLAG(F_TIME))
!                       printf("time=%ld.%09ld ", (long)cur->st_mtimespec.tv_sec,
                            cur->st_mtimespec.tv_nsec);
                if (MATCHFLAG(F_CKSUM))
                        printf("cksum=%lu ", cur->cksum);



Home | Main Index | Thread Index | Old Index