From sec@42.org  Thu Feb 19 05:43:46 2004
Return-Path: <sec@42.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 2AD0A16A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 19 Feb 2004 05:43:46 -0800 (PST)
Received: from ice.42.org (ice.42.org [194.77.3.162])
	by mx1.FreeBSD.org (Postfix) with ESMTP id DE96A43D1D
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 19 Feb 2004 05:43:45 -0800 (PST)
	(envelope-from sec@42.org)
Received: by ice.42.org (Postfix, from userid 1000)
	id 6BEAE1CE37; Thu, 19 Feb 2004 14:43:44 +0100 (CET)
Message-Id: <20040219134344.6BEAE1CE37@ice.42.org>
Date: Thu, 19 Feb 2004 14:43:44 +0100 (CET)
From: Stefan `Sec` Zehl <sec@42.org>
Reply-To: Stefan `Sec` Zehl <sec@42.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: strptime fails on %z
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         63064
>Category:       kern
>Synopsis:       [patch] strptime(3) fails on %z
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    delphij
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Feb 19 05:50:05 PST 2004
>Closed-Date:    Sun Jul 26 09:01:49 UTC 2009
>Last-Modified:  Sun Jul 26 09:10:02 UTC 2009
>Originator:     Stefan `Sec` Zehl
>Release:        FreeBSD 4.9-STABLE i386
>Organization:
>Environment:
System: FreeBSD ice 4.9-STABLE FreeBSD 4.9-STABLE #11: Sun Jan 25 15:43:27 CET 2004 root@ice:/export/obj/export/src/sys/ICE i386

	
>Description:

strptime fails to convert %z

>How-To-Repeat:

ice:~>date -j -f '%d/%b/%Y:%T %z' '19/Feb/2004:12:23:05 +0200' '+%T %z'
Warning: Ignoring 5 extraneous characters in date string (+0200)
12:23:05 +0100

As we can see, it ignores %z completely, and the returned time has
the local timezone (+0100, CET) instead of the correct one (+0200).

>Fix:

	


>Release-Note:
>Audit-Trail:

From: Makoto Matsushita <matusita@jp.FreeBSD.org>
To: bug-followup@FreeBSD.org
Cc: <sec@42.org>
Subject: Re: bin/63064: strptime fails on %z
Date: Fri, 20 Feb 2004 03:21:20 +0900

 sec> strptime fails to convert %z
 
 It can be considered that this is not a bug, and "by design".  If
 there's a bug, it is in strptime(3) manual page which says "All
 conversion specifications are identical to those described in
 strftime(3)," apparently that's not true.
 
 From strftime(3) manpage:
 
      The strftime() function conforms to ISO/IEC 9899:1990 (``ISO C89'') with
      a lot of extensions including `%C', `%D', `%E*', `%e', `%G', `%g', `%h',
      `%k', `%l', `%n', `%O*', `%R', `%r', `%s', `%T', `%t', `%u', `%V', `%z',
      `%+'.
 
 Since '%z' format is not defined in th standard, it would be ok that
 strptime(3) doesn't support '%z'.  Of course, it would be even better
 that strptime(3) supports all format characters in strftime(3).
 
 -- -
 Makoto `MAR' Matsushita

From: Stefan `Sec` Zehl <sec@42.org>
To: Makoto Matsushita <matusita@jp.FreeBSD.org>
Cc: bug-followup@FreeBSD.org
Subject: Re: bin/63064: strptime fails on %z
Date: Fri, 20 Feb 2004 00:21:50 +0100

 On Fri, Feb 20, 2004 at 03:21 +0900, Makoto Matsushita wrote:
 > Since '%z' format is not defined in th standard, it would be ok that
 > strptime(3) doesn't support '%z'.  Of course, it would be even better
 > that strptime(3) supports all format characters in strftime(3).
 
 I see. What about this patch?
 
 --- /usr/src/lib/libc/stdtime/strptime.c.org	Tue Mar 12 18:24:54 2002
 +++ /usr/src/lib/libc/stdtime/strptime.c	Thu Feb 19 23:54:43 2004
 @@ -492,6 +492,29 @@
  					ptr++;
  			break;
  
 +		case 'z':
 +			if(*buf==0 || (buf[0]!='+' && buf[0] != '-'))
 +				break;
 +
 +			{
 +			signed char sign;
 +
 +			sign = (buf++[0] == '-') ? -1 : +1;
 +
 +			len = 4;
 +			for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) {
 +				i *= 10;
 +				i += *buf - '0';
 +				len--;
 +			}
 +
 +			tm->tm_hour-= sign*(i/100);
 +			tm->tm_min-= sign*(i%100);
 +			got_GMT=1;
 +
 +			}
 +			break;
 +
  		case 'Z':
  			{
  			const char *cp;
 
 
 CU,
     Sec
 -- 
 Cultures consist of people, and the traditional way to learn Unix culture is
 from other people and through the folklore, by osmosis.

From: "N.J. Mann" <njm@njm.me.uk>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/63064: strptime(3) fails %z
Date: Tue, 23 Sep 2008 17:16:47 +0100

 --UlVJffcvxoiEqYs2
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 I have been using an updated version of this patch (see below for my own
 version) for over a year (6-STABLE and recently 7-STABLE) as part of my
 anti-spam measures (date(1) called from procmail(1)) - if the date of a
 message is more than one hour in the future or two days in the past it
 is suspicious - with great affect.  I would really like to see this, or
 something very similar, incorporated into the official version of
 strptime(3).
 
 
 --UlVJffcvxoiEqYs2
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename="strptime.%z.patch.txt"
 
 --- lib/libc/stdtime/strptime.c~	2003-11-17 04:19:15.000000000 +0000
 +++ lib/libc/stdtime/strptime.c	2007-08-27 18:40:00.000000000 +0100
 @@ -490,6 +490,28 @@
  					ptr++;
  			break;
  
 +		case 'z':
 +			{
 +			int sign;
 +
 +			if (*buf != '+' && *buf != '-')
 +				break;
 +
 +			sign = (*buf++ == '-') ? -1 : +1;
 +
 +			len = 4;
 +			for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) {
 +				i *= 10;
 +				i += *buf - '0';
 +				len--;
 +			}
 +
 +			tm->tm_hour -= sign * (i / 100);
 +			tm->tm_min -= sign * (i % 100);
 +			*GMTp = 1;
 +			}
 +			break;
 +
  		case 'Z':
  			{
  			const char *cp;
 
 --UlVJffcvxoiEqYs2--

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/63064: commit references a PR
Date: Thu, 25 Jun 2009 23:59:37 +0000 (UTC)

 Author: delphij
 Date: Thu Jun 25 23:59:23 2009
 New Revision: 195015
 URL: http://svn.freebsd.org/changeset/base/195015
 
 Log:
   Implement %z for strptime.
   
   PR:		kern/63064
   Submitted by:	Stefan `Sec` Zehl <sec 42 org> (with some small changes)
   MFC after:	1 month
 
 Modified:
   head/lib/libc/stdtime/strptime.c
 
 Modified: head/lib/libc/stdtime/strptime.c
 ==============================================================================
 --- head/lib/libc/stdtime/strptime.c	Thu Jun 25 23:22:25 2009	(r195014)
 +++ head/lib/libc/stdtime/strptime.c	Thu Jun 25 23:59:23 2009	(r195015)
 @@ -514,6 +514,34 @@ label:
  			}
  			}
  			break;
 +
 +		case 'z':
 +			{
 +			int sign = 1;
 +
 +			if (*buf != '+') {
 +				if (*buf == '-')
 +					sign = -1;
 +				else
 +					return 0;
 +			}
 +
 +			buf++;
 +			i = 0;
 +			for (len = 4; len > 0; len--) {
 +				if (isdigit((int)*buf)) {
 +					i *= 10;
 +					i += *buf - '0';
 +					buf++;
 +				} else
 +					return 0;
 +			}
 +
 +			tm->tm_hour -= sign * (i / 100);
 +			tm->tm_min  -= sign * (i % 100);
 +			*GMTp = 1;
 +			}
 +			break;
  		}
  	}
  	return (char *)buf;
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: delphij 
State-Changed-When: Fri Jun 26 00:00:10 UTC 2009 
State-Changed-Why:  
A patch has been applied against -HEAD, MFC reminder, 
thanks for your submission! 


Responsible-Changed-From-To: freebsd-bugs->delphij 
Responsible-Changed-By: delphij 
Responsible-Changed-When: Fri Jun 26 00:00:10 UTC 2009 
Responsible-Changed-Why:  
Take. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=63064 
State-Changed-From-To: patched->closed 
State-Changed-By: delphij 
State-Changed-When: Sun Jul 26 09:01:27 UTC 2009 
State-Changed-Why:  
Patch MFC'ed to 6-STABLE and 7-STABLE, thanks for your submission! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=63064 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/63064: commit references a PR
Date: Sun, 26 Jul 2009 09:00:49 +0000 (UTC)

 Author: delphij
 Date: Sun Jul 26 09:00:37 2009
 New Revision: 195888
 URL: http://svn.freebsd.org/changeset/base/195888
 
 Log:
   Implement %z for strptime.
   
   PR:		kern/63064
   Submitted by:	Stefan `Sec` Zehl <sec 42 org> (with some small changes)
 
 Modified:
   stable/7/lib/libc/   (props changed)
   stable/7/lib/libc/stdtime/strptime.c
 
 Modified: stable/7/lib/libc/stdtime/strptime.c
 ==============================================================================
 --- stable/7/lib/libc/stdtime/strptime.c	Sun Jul 26 08:47:00 2009	(r195887)
 +++ stable/7/lib/libc/stdtime/strptime.c	Sun Jul 26 09:00:37 2009	(r195888)
 @@ -514,6 +514,34 @@ label:
  			}
  			}
  			break;
 +
 +		case 'z':
 +			{
 +			int sign = 1;
 +
 +			if (*buf != '+') {
 +				if (*buf == '-')
 +					sign = -1;
 +				else
 +					return 0;
 +			}
 +
 +			buf++;
 +			i = 0;
 +			for (len = 4; len > 0; len--) {
 +				if (isdigit((int)*buf)) {
 +					i *= 10;
 +					i += *buf - '0';
 +					buf++;
 +				} else
 +					return 0;
 +			}
 +
 +			tm->tm_hour -= sign * (i / 100);
 +			tm->tm_min  -= sign * (i % 100);
 +			*GMTp = 1;
 +			}
 +			break;
  		}
  	}
  	return (char *)buf;
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/63064: commit references a PR
Date: Sun, 26 Jul 2009 09:01:35 +0000 (UTC)

 Author: delphij
 Date: Sun Jul 26 09:01:15 2009
 New Revision: 195889
 URL: http://svn.freebsd.org/changeset/base/195889
 
 Log:
   Implement %z for strptime.
   
   PR:		kern/63064
   Submitted by:	Stefan `Sec` Zehl <sec 42 org> (with some small changes)
 
 Modified:
   stable/6/lib/libc/   (props changed)
   stable/6/lib/libc/stdtime/strptime.c
 
 Modified: stable/6/lib/libc/stdtime/strptime.c
 ==============================================================================
 --- stable/6/lib/libc/stdtime/strptime.c	Sun Jul 26 09:00:37 2009	(r195888)
 +++ stable/6/lib/libc/stdtime/strptime.c	Sun Jul 26 09:01:15 2009	(r195889)
 @@ -514,6 +514,34 @@ label:
  			}
  			}
  			break;
 +
 +		case 'z':
 +			{
 +			int sign = 1;
 +
 +			if (*buf != '+') {
 +				if (*buf == '-')
 +					sign = -1;
 +				else
 +					return 0;
 +			}
 +
 +			buf++;
 +			i = 0;
 +			for (len = 4; len > 0; len--) {
 +				if (isdigit((int)*buf)) {
 +					i *= 10;
 +					i += *buf - '0';
 +					buf++;
 +				} else
 +					return 0;
 +			}
 +
 +			tm->tm_hour -= sign * (i / 100);
 +			tm->tm_min  -= sign * (i % 100);
 +			*GMTp = 1;
 +			}
 +			break;
  		}
  	}
  	return (char *)buf;
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
