util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] Pull Request
@ 2017-04-27  3:29 J William Piggott
  2017-05-02  9:13 ` Karel Zak
  0 siblings, 1 reply; 18+ messages in thread
From: J William Piggott @ 2017-04-27  3:29 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux, junk


 sys-utils/hwclock.c | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

The following changes since commit 85bfb519afcbccccb63849b1a348dde76ff6bb83:

  switch_root: unlink files without _DIRENT_HAVE_D_TYPE (2017-04-26 11:23:50 +0200)

are available in the git repository at:

  git@github.com:jwpi/util-linux.git 170419

for you to fetch changes up to 57415653a667cf2442d019f62287534931ab3da4:

  hwclock: use a consistent name for --predict (2017-04-26 23:19:56 -0400)

----------------------------------------------------------------
J William Piggott (4):
      hwclock: extra messages for debug only
      hwclock: make clock test mode message consistent
      hwclock: remove unneeded braces
      hwclock: use a consistent name for --predict

 sys-utils/hwclock.c | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 0/4] Pull Request
  2017-04-27  3:29 [PATCH 0/4] Pull Request J William Piggott
@ 2017-05-02  9:13 ` Karel Zak
  0 siblings, 0 replies; 18+ messages in thread
From: Karel Zak @ 2017-05-02  9:13 UTC (permalink / raw)
  To: J William Piggott; +Cc: util-linux, junk

On Wed, Apr 26, 2017 at 11:29:40PM -0400, J William Piggott wrote:
>       hwclock: extra messages for debug only
>       hwclock: make clock test mode message consistent
>       hwclock: remove unneeded braces
>       hwclock: use a consistent name for --predict

Applied, thanks.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH 0/4] pull request
@ 2017-05-31 18:45 J William Piggott
  2017-06-01  8:54 ` Karel Zak
  0 siblings, 1 reply; 18+ messages in thread
From: J William Piggott @ 2017-05-31 18:45 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux


docs: various changes; see patches for details.

The following changes since commit 3947ca4ca9737d830f54658ef353f5626c0d0282:

  build-sys: ncurses headers cleanup (2017-05-31 11:01:46 +0200)

are available in the git repository at:

  git@github.com:jwpi/util-linux.git 170529

for you to fetch changes up to 80008bcae9a1aed3d38507a319155a69c4414509:

  docs: move source-code-management.txt to README (2017-05-31 11:36:47 -0400)

----------------------------------------------------------------
J William Piggott (4):
      docs: update v2.30-ReleaseNotes
      docs: update howto-contribute.txt
      docs: update howto-contribute.txt
      docs: move source-code-management.txt to README

 Documentation/howto-contribute.txt        | 201 +++++++++++++++---------------
 Documentation/release-schedule.txt        |   2 +-
 Documentation/releases/v2.30-ReleaseNotes |  38 +++---
 Documentation/source-code-management.txt  |  38 ------
 README                                    | 121 +++++++++++++-----
 5 files changed, 215 insertions(+), 185 deletions(-)
 delete mode 100644 Documentation/source-code-management.txt

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 0/4] pull request
  2017-05-31 18:45 J William Piggott
@ 2017-06-01  8:54 ` Karel Zak
  0 siblings, 0 replies; 18+ messages in thread
From: Karel Zak @ 2017-06-01  8:54 UTC (permalink / raw)
  To: J William Piggott; +Cc: util-linux

On Wed, May 31, 2017 at 02:45:23PM -0400, J William Piggott wrote:
>   git@github.com:jwpi/util-linux.git 170529

Applied, thanks.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH 0/4] pull request
@ 2017-06-25 21:45 J William Piggott
  2017-06-26  8:27 ` Karel Zak
  0 siblings, 1 reply; 18+ messages in thread
From: J William Piggott @ 2017-06-25 21:45 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux


* Rudi didn't like cluttering boilerplate.c with seldom used USAGE_*
  constants and I don't disagree with that point. I do think they should
  be in the file for new contributor discovery purposes. As a compromise
  I added the missing ones as a comment.

* the newly added USAGE_COLUMNS could be used in disk-utils/fdisk-list.c:432
  if Karel wants to drop the ' (for -o)'. I did not change it.

* I couldn't test the blkzone change to USAGE_COMMANDS, but I expect it to
  be okay.
   configure: WARNING: linux/blkzoned.h header not found; not building blkzone


The following changes since commit 2a14beb4e9c6cdf4466993741d86e45dd57ddef3:

  agetty: fix login name DEL/CTRL^U issue (2017-06-23 14:26:47 +0200)

are available in the git repository at:

  git@github.com:jwpi/util-linux.git 170622

for you to fetch changes up to 7948117da5654311dba59b256d9a017d56877592:

  Docs: move option naming to howto-contribute.txt (2017-06-24 15:22:49 -0400)

----------------------------------------------------------------
J William Piggott (4):
      include/c.h: add USAGE_COMMANDS and USAGE_COLUMNS
      Docs: add a comment for constants to boilerplate.c
      Docs: update howto-usage-function.txt
      Docs: move option naming to howto-contribute.txt

 Documentation/boilerplate.c            |  8 +--
 Documentation/howto-contribute.txt     | 25 +++++++++
 Documentation/howto-usage-function.txt | 97 +++++++++++++---------------------
 disk-utils/sfdisk.c                    |  2 +-
 include/c.h                            |  4 +-
 login-utils/lslogins.c                 |  6 +--
 misc-utils/findmnt.c                   |  3 +-
 sys-utils/blkzone.c                    |  2 +-
 sys-utils/lscpu.c                      |  3 +-
 sys-utils/lsmem.c                      |  5 +-
 sys-utils/wdctl.c                      |  3 +-
 11 files changed, 78 insertions(+), 80 deletions(-)

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 0/4] pull request
  2017-06-25 21:45 [PATCH 0/4] pull request J William Piggott
@ 2017-06-26  8:27 ` Karel Zak
  2017-06-26 12:11   ` Karel Zak
  2017-06-26 13:47   ` J William Piggott
  0 siblings, 2 replies; 18+ messages in thread
From: Karel Zak @ 2017-06-26  8:27 UTC (permalink / raw)
  To: J William Piggott; +Cc: util-linux

On Sun, Jun 25, 2017 at 05:45:56PM -0400, J William Piggott wrote:
> 
> * Rudi didn't like cluttering boilerplate.c with seldom used USAGE_*
>   constants and I don't disagree with that point. I do think they should
>   be in the file for new contributor discovery purposes. As a compromise
>   I added the missing ones as a comment.
> 
> * the newly added USAGE_COLUMNS could be used in disk-utils/fdisk-list.c:432
>   if Karel wants to drop the ' (for -o)'. I did not change it.

I think USAGE_COLUMNS should be good enough everywhere and the
additional notes (like ' (for -o)') are unnecessary.

Maybe we can change the text to "Available output columns:" to make it
more specific for readers.

    Karel


-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 0/4] pull request
  2017-06-26  8:27 ` Karel Zak
@ 2017-06-26 12:11   ` Karel Zak
  2017-06-26 13:47   ` J William Piggott
  1 sibling, 0 replies; 18+ messages in thread
From: Karel Zak @ 2017-06-26 12:11 UTC (permalink / raw)
  To: J William Piggott; +Cc: util-linux

On Mon, Jun 26, 2017 at 10:27:44AM +0200, Karel Zak wrote:
> On Sun, Jun 25, 2017 at 05:45:56PM -0400, J William Piggott wrote:
> > 
> > * Rudi didn't like cluttering boilerplate.c with seldom used USAGE_*
> >   constants and I don't disagree with that point. I do think they should
> >   be in the file for new contributor discovery purposes. As a compromise
> >   I added the missing ones as a comment.
> > 
> > * the newly added USAGE_COLUMNS could be used in disk-utils/fdisk-list.c:432
> >   if Karel wants to drop the ' (for -o)'. I did not change it.
> 
> I think USAGE_COLUMNS should be good enough everywhere and the
> additional notes (like ' (for -o)') are unnecessary.
> 
> Maybe we can change the text to "Available output columns:" to make it
> more specific for readers.

 Implemented & pull request merged. Thanks.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 0/4] pull request
  2017-06-26  8:27 ` Karel Zak
  2017-06-26 12:11   ` Karel Zak
@ 2017-06-26 13:47   ` J William Piggott
  2017-06-26 14:25     ` Karel Zak
  1 sibling, 1 reply; 18+ messages in thread
From: J William Piggott @ 2017-06-26 13:47 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux



On 06/26/2017 04:27 AM, Karel Zak wrote:
> On Sun, Jun 25, 2017 at 05:45:56PM -0400, J William Piggott wrote:
>>
>> * Rudi didn't like cluttering boilerplate.c with seldom used USAGE_*
>>   constants and I don't disagree with that point. I do think they should
>>   be in the file for new contributor discovery purposes. As a compromise
>>   I added the missing ones as a comment.
>>
>> * the newly added USAGE_COLUMNS could be used in disk-utils/fdisk-list.c:432
>>   if Karel wants to drop the ' (for -o)'. I did not change it.
> 
> I think USAGE_COLUMNS should be good enough everywhere and the
> additional notes (like ' (for -o)') are unnecessary.
> 
> Maybe we can change the text to "Available output columns:" to make it
> more specific for readers.

Since we cannot guarantee that the 'output' option name will always be
available. It might be better to stay generic with the header and
instead create the reference in the option description like:

 -o, --output <list>    columns to display (see Columns:)

 Columns:
      SOURCE  source device
      ...

This would also keep the Columns header format consistent with the others.

On a somewhat related note; in recent discussion I've been trying to
promote the idea of using consistent language. For example, with all of
the synonyms: output, show, to stdout, display, print, etc. I think it
would be helpful to both users and translators to choose one to be used
consistently. Especially for technical writing it is important to use
consistent terms.

An idea from the Linux man-pages project is that man-pages.7 has a list
of preferred terms/spellings; perhaps util-linux could have a list of
preferred terms to be used in documentation and message strings?

We also might want to consider replacing Documentation/howto-man-page.txt
with a link to, or a copy of, man-pages.7. Michael and company have
added a lot to it in recent times.


> 
>     Karel
> 
> 

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 0/4] pull request
  2017-06-26 13:47   ` J William Piggott
@ 2017-06-26 14:25     ` Karel Zak
  0 siblings, 0 replies; 18+ messages in thread
From: Karel Zak @ 2017-06-26 14:25 UTC (permalink / raw)
  To: J William Piggott; +Cc: util-linux

On Mon, Jun 26, 2017 at 09:47:42AM -0400, J William Piggott wrote:
> 
> 
> On 06/26/2017 04:27 AM, Karel Zak wrote:
> > On Sun, Jun 25, 2017 at 05:45:56PM -0400, J William Piggott wrote:
> >>
> >> * Rudi didn't like cluttering boilerplate.c with seldom used USAGE_*
> >>   constants and I don't disagree with that point. I do think they should
> >>   be in the file for new contributor discovery purposes. As a compromise
> >>   I added the missing ones as a comment.
> >>
> >> * the newly added USAGE_COLUMNS could be used in disk-utils/fdisk-list.c:432
> >>   if Karel wants to drop the ' (for -o)'. I did not change it.
> > 
> > I think USAGE_COLUMNS should be good enough everywhere and the
> > additional notes (like ' (for -o)') are unnecessary.
> > 
> > Maybe we can change the text to "Available output columns:" to make it
> > more specific for readers.
> 
> Since we cannot guarantee that the 'output' option name will always be
> available.

I have already pushed "Available output columns:" :-) 

The "output" does not mean any option in this case.

> It might be better to stay generic with the header and
> instead create the reference in the option description like:
> 
>  -o, --output <list>    columns to display (see Columns:)
> 
>  Columns:
>       SOURCE  source device
>       ...

Anyway, I like this "see Columns:" idea. Go ahead and send patch.

> On a somewhat related note; in recent discussion I've been trying to
> promote the idea of using consistent language. For example, with all of
> the synonyms: output, show, to stdout, display, print, etc. I think it
> would be helpful to both users and translators to choose one to be used
> consistently. Especially for technical writing it is important to use
> consistent terms.
> 
> An idea from the Linux man-pages project is that man-pages.7 has a list
> of preferred terms/spellings; perhaps util-linux could have a list of
> preferred terms to be used in documentation and message strings?

Sounds good. (but I hope we will have no endless "bike-shed
color" discussion about the terms)

> We also might want to consider replacing Documentation/howto-man-page.txt
> with a link to, or a copy of, man-pages.7. Michael and company have
> added a lot to it in recent times.

Documentation/howto-man-page.txt is a template, if you want to write new
tool than it should be good enough to cp(1) this template and use it.
I'd like to keep it there.

We can rename the file to Documentation/boilerplate.1 and rewrite
Documentation/howto-man-page.txt to the real how-to with link to the
Michal's man-pages.7.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH 0/4] Pull Request
@ 2017-07-16 17:46 J William Piggott
  2017-07-17 10:03 ` Karel Zak
  0 siblings, 1 reply; 18+ messages in thread
From: J William Piggott @ 2017-07-16 17:46 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux


The following changes since commit 8ffa3b651d7e74acba8f1d831b7f68fdb3c66aae:

  libfdisk: make fdisk compliant to UEFI/GPT specification on PMBR (2017-07-14 12:48:18 +0200)

are available in the git repository at:

  git@github.com:jwpi/util-linux.git 170711

for you to fetch changes up to c26ddc568f3fb26b45a22cbf89d3294113e70377:

  hwclock: improve RTC epoch messages (2017-07-16 08:41:54 -0400)

----------------------------------------------------------------
J William Piggott (4):
      hwclock: --epoch presence test fails
      hwclock: remove dead ioctl check
      hwclock: improve RTC epoch messages
      hwclock: improve RTC epoch messages

 sys-utils/hwclock-rtc.c | 56 +++++++++++++++++++------------------------------
 sys-utils/hwclock.8.in  |  3 +++
 sys-utils/hwclock.c     | 24 +++++++--------------
 sys-utils/hwclock.h     |  2 +-
 4 files changed, 32 insertions(+), 53 deletions(-)


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 0/4] Pull Request
  2017-07-16 17:46 J William Piggott
@ 2017-07-17 10:03 ` Karel Zak
  0 siblings, 0 replies; 18+ messages in thread
From: Karel Zak @ 2017-07-17 10:03 UTC (permalink / raw)
  To: J William Piggott; +Cc: util-linux

On Sun, Jul 16, 2017 at 01:46:38PM -0400, J William Piggott wrote:
>  sys-utils/hwclock-rtc.c | 56 +++++++++++++++++++------------------------------
>  sys-utils/hwclock.8.in  |  3 +++
>  sys-utils/hwclock.c     | 24 +++++++--------------
>  sys-utils/hwclock.h     |  2 +-
>  4 files changed, 32 insertions(+), 53 deletions(-)

Applied, thanks.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH 0/4] Pull Request
@ 2017-10-23  0:37 J William Piggott
  0 siblings, 0 replies; 18+ messages in thread
From: J William Piggott @ 2017-10-23  0:37 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux


This patch set address four bugs. Three are related to ISO 8601 formats
and the fourth is a tangentially related bug in hwclock. 

Patch 0002 increases the ISO 8601 buffer macro from 32 to 42 which should
work for the first three, and may be usable in the last four files:
  login-utils/last.c:1039	buffer size 32
  misc-utils/uuidparse.c:231	uses ISO_8601_BUFSIZ + 4
  login-utils/utmpdump.c:94	buffer size 40
  login-utils/lslogins.c:316	buffer size 64
  sys-utils/lsipc.c:1328	buffer size 64
  sys-utils/dmesg.c:887		buffer size 256
  term-utils/script.c:351	uses BUFSIZ (8K on my system)

I haven't tested it on them.

The the final patch adds some common ISO timestamp format masks.

The following changes since commit b41bac08abadbea9bac7a093c995ca53d86c76f1:

  build-sys: move rfkill to /usr/sbin (2017-10-20 14:59:16 +0200)

are available in the git repository at:

  git@github.com:jwpi/util-linux.git 170925

for you to fetch changes up to a9f92c6d1f25f4111f1334bdb2dd96f8b4ccb9ba:

  lib/timeutils: add common ISO timestamp masks (2017-10-21 20:55:01 -0400)

----------------------------------------------------------------
J William Piggott (4):
      hwclock: add iso-8601 overflow check
      lib/timeutils: ISO_8601_BUFSIZ too small
      lib/timeutils: add get_gmtoff()
      lib/timeutils: add common ISO timestamp masks

 include/timeutils.h    | 23 ++++++++++++-----
 lib/timeutils.c        | 70 +++++++++++++++++++++++++++++++++++++++++++++++---
 login-utils/last.c     |  2 +-
 login-utils/lslogins.c |  3 +--
 login-utils/utmpdump.c |  4 +--
 misc-utils/uuidparse.c | 10 ++------
 sys-utils/dmesg.c      |  4 +--
 sys-utils/hwclock.c    | 23 +++++++----------
 sys-utils/lsipc.c      |  2 +-
 sys-utils/rfkill.c     |  8 ++----
 term-utils/script.c    |  8 ++----
 11 files changed, 103 insertions(+), 54 deletions(-)

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH 0/4] Pull Request
@ 2017-12-10 15:47 J William Piggott
  2017-12-10 15:48 ` [PATCH 1/4] lib/timeutils.c: bug fix Segmentation fault J William Piggott
                   ` (4 more replies)
  0 siblings, 5 replies; 18+ messages in thread
From: J William Piggott @ 2017-12-10 15:47 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux


The following changes since commit 44d753407d6b751f022ef234c85785ccd99c5590:

  tests: unlocks on failed ts_scsi_debug_init (2017-12-07 15:08:29 +0100)

are available in the git repository at:

  git@github.com:jwpi/util-linux.git 171121

for you to fetch changes up to 6cdc7b9c02b251120eb014c4dbc2387d47e7fb46:

  lib/timeutils.c: warn format_iso_time() overflow (2017-12-09 18:43:29 -0500)

----------------------------------------------------------------
J William Piggott (4):
      lib/timeutils.c: bug fix Segmentation fault
      lib/timeutils.c:strxxx_iso: test conversion errors
      lib/timeutils.c:strxxx_iso: do not wrap tm_year
      lib/timeutils.c: warn format_iso_time() overflow

 lib/timeutils.c     | 46 +++++++++++++++++++++++++++++++---------------
 sys-utils/hwclock.c |  5 ++---
 2 files changed, 33 insertions(+), 18 deletions(-)

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH 1/4] lib/timeutils.c: bug fix Segmentation fault
  2017-12-10 15:47 [PATCH 0/4] Pull Request J William Piggott
@ 2017-12-10 15:48 ` J William Piggott
  2017-12-10 15:54 ` [PATCH 2/4] lib/timeutils.c:strxxx_iso: test conversion errors J William Piggott
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 18+ messages in thread
From: J William Piggott @ 2017-12-10 15:48 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux


Use reentrant time functions to avoid sending a NULL pointer to
format_iso_time() (and to be reentrant ;). Followup commits test for
errors and tm_year wrapping (illustrated below).

hwclock --utc --noadjfile --predict --date '67768034678849400 seconds'
Segmentation fault

Patched
hwclock --utc --noadjfile --predict --date '67768034678849400 seconds'
-2147481748-01-00 00:10:46.000000-05:00

Signed-off-by: J William Piggott <elseifthen@gmx.com>
---
 lib/timeutils.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/timeutils.c b/lib/timeutils.c
index fdaa2d4a9..994073700 100644
--- a/lib/timeutils.c
+++ b/lib/timeutils.c
@@ -462,9 +462,9 @@ int strtimeval_iso(struct timeval *tv, int flags, char *buf, size_t bufsz)
 	struct tm tm;
 
 	if (flags & ISO_GMTIME)
-		tm = *gmtime(&tv->tv_sec);
+		gmtime_r(&tv->tv_sec, &tm);
 	else
-		tm = *localtime(&tv->tv_sec);
+		localtime_r(&tv->tv_sec, &tm);
 	return format_iso_time(&tm, tv->tv_usec, flags, buf, bufsz);
 }
 
@@ -480,9 +480,9 @@ int strtime_iso(const time_t *t, int flags, char *buf, size_t bufsz)
 	struct tm tm;
 
 	if (flags & ISO_GMTIME)
-		tm = *gmtime(t);
+		gmtime_r(t, &tm);
 	else
-		tm = *localtime(t);
+		localtime_r(t, &tm);
 	return format_iso_time(&tm, 0, flags, buf, bufsz);
 }
 

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 2/4] lib/timeutils.c:strxxx_iso: test conversion errors
  2017-12-10 15:47 [PATCH 0/4] Pull Request J William Piggott
  2017-12-10 15:48 ` [PATCH 1/4] lib/timeutils.c: bug fix Segmentation fault J William Piggott
@ 2017-12-10 15:54 ` J William Piggott
  2017-12-10 15:55 ` [PATCH 3/4] lib/timeutils.c:strxxx_iso: do not wrap tm_year J William Piggott
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 18+ messages in thread
From: J William Piggott @ 2017-12-10 15:54 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux


Test for libc time conversion errors in ISO time format functions.

hwclock --utc --noadjfile --predict --date '67768034678846520 seconds'
Segmentation fault

Patched:
hwclock --utc --noadjfile --predict --date '67768034678846520 seconds'
hwclock: time 67768036191695381 is out of range.

Comparable to date(1):
date --date '67768034678846520 seconds'
date: time 67768036191695384 is out of range

Signed-off-by: J William Piggott <elseifthen@gmx.com>
---
 lib/timeutils.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/lib/timeutils.c b/lib/timeutils.c
index 994073700..dd763ecc3 100644
--- a/lib/timeutils.c
+++ b/lib/timeutils.c
@@ -460,12 +460,18 @@ static int format_iso_time(struct tm *tm, suseconds_t usec, int flags, char *buf
 int strtimeval_iso(struct timeval *tv, int flags, char *buf, size_t bufsz)
 {
 	struct tm tm;
+	struct tm *rc;
 
 	if (flags & ISO_GMTIME)
-		gmtime_r(&tv->tv_sec, &tm);
+		rc = gmtime_r(&tv->tv_sec, &tm);
 	else
-		localtime_r(&tv->tv_sec, &tm);
-	return format_iso_time(&tm, tv->tv_usec, flags, buf, bufsz);
+		rc = localtime_r(&tv->tv_sec, &tm);
+
+	if (rc)
+		return format_iso_time(&tm, tv->tv_usec, flags, buf, bufsz);
+
+	warnx(_("time %ld is out of range."), tv->tv_sec);
+	return -1;
 }
 
 /* struct tm to ISO 8601 */
@@ -478,12 +484,18 @@ int strtm_iso(struct tm *tm, int flags, char *buf, size_t bufsz)
 int strtime_iso(const time_t *t, int flags, char *buf, size_t bufsz)
 {
 	struct tm tm;
+	struct tm *rc;
 
 	if (flags & ISO_GMTIME)
-		gmtime_r(t, &tm);
+		rc = gmtime_r(t, &tm);
 	else
-		localtime_r(t, &tm);
-	return format_iso_time(&tm, 0, flags, buf, bufsz);
+		rc = localtime_r(t, &tm);
+
+	if (rc)
+		return format_iso_time(&tm, 0, flags, buf, bufsz);
+
+	warnx(_("time %ld is out of range."), (long)t);
+	return -1;
 }
 
 /* relative time functions */

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 3/4] lib/timeutils.c:strxxx_iso: do not wrap tm_year
  2017-12-10 15:47 [PATCH 0/4] Pull Request J William Piggott
  2017-12-10 15:48 ` [PATCH 1/4] lib/timeutils.c: bug fix Segmentation fault J William Piggott
  2017-12-10 15:54 ` [PATCH 2/4] lib/timeutils.c:strxxx_iso: test conversion errors J William Piggott
@ 2017-12-10 15:55 ` J William Piggott
  2017-12-10 15:56 ` [PATCH 4/4] lib/timeutils.c: warn format_iso_time() overflow J William Piggott
  2017-12-11 14:53 ` [PATCH 0/4] Pull Request Karel Zak
  4 siblings, 0 replies; 18+ messages in thread
From: J William Piggott @ 2017-12-10 15:55 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux


Year can wrap when adding the tm struct epoch during iso formatting:
hwclock --utc --noadjfile --predict --date '67768034678844900 seconds'
-2147481749-12-31 23:59:59.000000-05:00

Patched:
hwclock --utc --noadjfile --predict --date '67768034678844900 seconds'
2147485547-12-31 23:59:59.000000-05:00

Comparable to date(1):
date -Ins --date '67768034678844900 seconds'
2147485547-12-31T23:59:59,547886165-0500

Note: the 'seconds' argument is relative to the current time, so
      reaching this max year output is a moving target. The values shown
      above were invalid one second later. They then overflow tm_year
      upon conversion with localtime(3) and friends, which causes them
      to return NULL indicating that an error occurred.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
---
 lib/timeutils.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/lib/timeutils.c b/lib/timeutils.c
index dd763ecc3..a7459d2b6 100644
--- a/lib/timeutils.c
+++ b/lib/timeutils.c
@@ -406,8 +406,9 @@ static int format_iso_time(struct tm *tm, suseconds_t usec, int flags, char *buf
 	int len;
 
 	if (flags & ISO_DATE) {
-		len = snprintf(p, bufsz, "%4d-%.2d-%.2d", tm->tm_year + 1900,
-						tm->tm_mon + 1, tm->tm_mday);
+		len = snprintf(p, bufsz, "%4ld-%.2d-%.2d",
+			       tm->tm_year + (long) 1900,
+			       tm->tm_mon + 1, tm->tm_mday);
 		if (len < 0 || (size_t) len > bufsz)
 			return -1;
 		bufsz -= len;
@@ -423,7 +424,7 @@ static int format_iso_time(struct tm *tm, suseconds_t usec, int flags, char *buf
 
 	if (flags & ISO_TIME) {
 		len = snprintf(p, bufsz, "%02d:%02d:%02d", tm->tm_hour,
-						 tm->tm_min, tm->tm_sec);
+			       tm->tm_min, tm->tm_sec);
 		if (len < 0 || (size_t) len > bufsz)
 			return -1;
 		bufsz -= len;
@@ -451,7 +452,7 @@ static int format_iso_time(struct tm *tm, suseconds_t usec, int flags, char *buf
 		int zmin  = abs(tmin % 60);
 		len = snprintf(p, bufsz, "%+03d:%02d", zhour,zmin);
 		if (len < 0 || (size_t) len > bufsz)
-		return -1;
+			return -1;
 	}
 	return 0;
 }

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 4/4] lib/timeutils.c: warn format_iso_time() overflow
  2017-12-10 15:47 [PATCH 0/4] Pull Request J William Piggott
                   ` (2 preceding siblings ...)
  2017-12-10 15:55 ` [PATCH 3/4] lib/timeutils.c:strxxx_iso: do not wrap tm_year J William Piggott
@ 2017-12-10 15:56 ` J William Piggott
  2017-12-11 14:53 ` [PATCH 0/4] Pull Request Karel Zak
  4 siblings, 0 replies; 18+ messages in thread
From: J William Piggott @ 2017-12-10 15:56 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux


Print a message when the format_iso_time() buffer is exceeded, because
there is more than one type of failure that returns -1.

Also remove the corresponding message from hwclock.c.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
---
 lib/timeutils.c     | 15 +++++++++------
 sys-utils/hwclock.c |  5 ++---
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/lib/timeutils.c b/lib/timeutils.c
index a7459d2b6..9c286aebc 100644
--- a/lib/timeutils.c
+++ b/lib/timeutils.c
@@ -410,14 +410,14 @@ static int format_iso_time(struct tm *tm, suseconds_t usec, int flags, char *buf
 			       tm->tm_year + (long) 1900,
 			       tm->tm_mon + 1, tm->tm_mday);
 		if (len < 0 || (size_t) len > bufsz)
-			return -1;
+			goto err;
 		bufsz -= len;
 		p += len;
 	}
 
 	if ((flags & ISO_DATE) && (flags & ISO_TIME)) {
 		if (bufsz < 1)
-			return -1;
+			goto err;
 		*p++ = (flags & ISO_T) ? 'T' : ' ';
 		bufsz--;
 	}
@@ -426,7 +426,7 @@ static int format_iso_time(struct tm *tm, suseconds_t usec, int flags, char *buf
 		len = snprintf(p, bufsz, "%02d:%02d:%02d", tm->tm_hour,
 			       tm->tm_min, tm->tm_sec);
 		if (len < 0 || (size_t) len > bufsz)
-			return -1;
+			goto err;
 		bufsz -= len;
 		p += len;
 	}
@@ -434,14 +434,14 @@ static int format_iso_time(struct tm *tm, suseconds_t usec, int flags, char *buf
 	if (flags & ISO_DOTUSEC) {
 		len = snprintf(p, bufsz, ".%06ld", (long) usec);
 		if (len < 0 || (size_t) len > bufsz)
-			return -1;
+			goto err;
 		bufsz -= len;
 		p += len;
 
 	} else if (flags & ISO_COMMAUSEC) {
 		len = snprintf(p, bufsz, ",%06ld", (long) usec);
 		if (len < 0 || (size_t) len > bufsz)
-			return -1;
+			goto err;
 		bufsz -= len;
 		p += len;
 	}
@@ -452,9 +452,12 @@ static int format_iso_time(struct tm *tm, suseconds_t usec, int flags, char *buf
 		int zmin  = abs(tmin % 60);
 		len = snprintf(p, bufsz, "%+03d:%02d", zhour,zmin);
 		if (len < 0 || (size_t) len > bufsz)
-			return -1;
+			goto err;
 	}
 	return 0;
+ err:
+	warnx(_("format_iso_time: buffer overflow."));
+	return -1;
 }
 
 /* timeval to ISO 8601 */
diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c
index e5f90a44e..71d2b17b7 100644
--- a/sys-utils/hwclock.c
+++ b/sys-utils/hwclock.c
@@ -556,10 +556,9 @@ display_time(struct timeval hwctime)
 {
 	char buf[ISO_BUFSIZ];
 
-	if (strtimeval_iso(&hwctime, ISO_TIMESTAMP_DOT, buf, sizeof(buf))) {
-		warnx(_("iso-8601 format overflow"));
+	if (strtimeval_iso(&hwctime, ISO_TIMESTAMP_DOT, buf, sizeof(buf)))
 		return EXIT_FAILURE;
-	}
+
 	printf("%s\n", buf);
 	return EXIT_SUCCESS;
 }

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH 0/4] Pull Request
  2017-12-10 15:47 [PATCH 0/4] Pull Request J William Piggott
                   ` (3 preceding siblings ...)
  2017-12-10 15:56 ` [PATCH 4/4] lib/timeutils.c: warn format_iso_time() overflow J William Piggott
@ 2017-12-11 14:53 ` Karel Zak
  4 siblings, 0 replies; 18+ messages in thread
From: Karel Zak @ 2017-12-11 14:53 UTC (permalink / raw)
  To: J William Piggott; +Cc: util-linux

On Sun, Dec 10, 2017 at 10:47:04AM -0500, J William Piggott wrote:
> J William Piggott (4):
>       lib/timeutils.c: bug fix Segmentation fault
>       lib/timeutils.c:strxxx_iso: test conversion errors
>       lib/timeutils.c:strxxx_iso: do not wrap tm_year
>       lib/timeutils.c: warn format_iso_time() overflow


Merged, thanks!

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2017-12-11 14:53 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-10 15:47 [PATCH 0/4] Pull Request J William Piggott
2017-12-10 15:48 ` [PATCH 1/4] lib/timeutils.c: bug fix Segmentation fault J William Piggott
2017-12-10 15:54 ` [PATCH 2/4] lib/timeutils.c:strxxx_iso: test conversion errors J William Piggott
2017-12-10 15:55 ` [PATCH 3/4] lib/timeutils.c:strxxx_iso: do not wrap tm_year J William Piggott
2017-12-10 15:56 ` [PATCH 4/4] lib/timeutils.c: warn format_iso_time() overflow J William Piggott
2017-12-11 14:53 ` [PATCH 0/4] Pull Request Karel Zak
  -- strict thread matches above, loose matches on Subject: below --
2017-10-23  0:37 J William Piggott
2017-07-16 17:46 J William Piggott
2017-07-17 10:03 ` Karel Zak
2017-06-25 21:45 [PATCH 0/4] pull request J William Piggott
2017-06-26  8:27 ` Karel Zak
2017-06-26 12:11   ` Karel Zak
2017-06-26 13:47   ` J William Piggott
2017-06-26 14:25     ` Karel Zak
2017-05-31 18:45 J William Piggott
2017-06-01  8:54 ` Karel Zak
2017-04-27  3:29 [PATCH 0/4] Pull Request J William Piggott
2017-05-02  9:13 ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).