Bug 8951 - touch -t 197001010000 will use seconds from localtime instead of 0
Summary: touch -t 197001010000 will use seconds from localtime instead of 0
Status: RESOLVED FIXED
Alias: None
Product: Busybox
Classification: Unclassified
Component: Standard Compliance (show other bugs)
Version: 1.24.x
Hardware: All Linux
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-05-19 13:10 UTC by Natanael Copa
Modified: 2016-08-03 13:37 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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