Bug 8951

Summary: touch -t 197001010000 will use seconds from localtime instead of 0
Product: Busybox Reporter: Natanael Copa <ncopa>
Component: Standard ComplianceAssignee: unassigned
Status: RESOLVED FIXED    
Severity: normal CC: busybox-cvs, sheets
Priority: P5    
Version: 1.24.x   
Target Milestone: ---   
Hardware: All   
OS: Linux   
Host: Target:
Build:

Description Natanael Copa 2016-05-19 13:10:37 UTC
POSIX says about `touch -t [[CC]YY]MMDDhhmm[.SS]`:

> If SS is not given a value, it is assumed to be zero.

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/touch.html

Busybox touch does not set it to zero, instead it uses the localtime's seconds.

To reproduce: 

  TZ=UTC strace busybox touch -t 197001010000 /tmp/foo

  ...
  utimensat(AT_FDCWD, "/tmp/foo", [{23, 0}, {23, 0}], 0) = 0
  ...


note that utimesat(2) is called with the seconds part to 23.

Doing the same with the .ss specified will correctly set the seconds part to 0:

  TZ=UTC strace busybox touch -t 197001010000.00 /tmp/foo

  ...
  utimensat(AT_FDCWD, "/tmp/foo", [{0, 0}, {0, 0}], 0) = 0
  ...


The reason is that the time_t struct is initialized with localtime instead of zero:
https://git.busybox.net/busybox/tree/coreutils/touch.c#n155
Comment 1 Natanael Copa 2016-08-03 13:37:41 UTC
fixed with commit b684d1b1864ba9d7968de5565823f8e42f1dc448