From nobody@FreeBSD.ORG Wed Feb 17 02:57:19 1999
Return-Path: <nobody@FreeBSD.ORG>
Received: by hub.freebsd.org (Postfix, from userid 32767)
	id 2F71A10E80; Wed, 17 Feb 1999 02:57:13 -0800 (PST)
Message-Id: <19990217105713.2F71A10E80@hub.freebsd.org>
Date: Wed, 17 Feb 1999 02:57:13 -0800 (PST)
From: tadf@kt.rim.or.jp
Sender: nobody@FreeBSD.ORG
To: freebsd-gnats-submit@freebsd.org
Subject: bug in strptime(3)
X-Send-Pr-Version: www-1.0

>Number:         10131
>Category:       bin
>Synopsis:       bug in strptime(3)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    sheldonh
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Feb 17 03:00:00 PST 1999
>Closed-Date:    Thu Dec 9 01:00:18 PST 1999
>Last-Modified:  Mon Jul 23 01:13:12 PDT 2001
>Originator:     Tadayoshi Funaba
>Release:        2.2.8-RELEASE
>Organization:
>Environment:
FreeBSD november.chronos 2.2.8-RELEASE FreeBSD 2.2.8-RELEASE #0: Wed Feb 10 17:03:59 JST 1999     tadf@november.chronos:/usr/src/sys/compile/NOVEMBER  i386

>Description:
%j should be 1-366, and map to 0-355 in tm_yday.
%S should be 0-60.
%w, %U and %W added.

>How-To-Repeat:
#include <stdio.h>
#include <time.h>

main()
{
        time_t t;
        struct tm tm;

        time(&t);
        tm = *localtime(&t);
        if (strptime("365", "%j", &tm))
                printf("%d\n", tm.tm_yday);
}

>Fix:
begin 644 p
M+2TM('-T<G!T:6UE+F,N;W)I9PE3=6X@4V5P(#$S(#`W.C(P.C0P(#$Y.3@*
M*RLK('-T<G!T:6UE+F,)36]N($9E8B`Q-2`P,#HS-#HQ-B`Q.3DY"D!`("TQ
M-3DL,3`@*S$U.2PQ,"!`0`H@"0D)"6D@*CT@,3`["B`)"0D):2`K/2`J8G5F
M("T@)S`G.PH@"0D)?0HM"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H@"0EC87-E
M("=D)SH*(`D)8V%S92`G92<Z"B`)"0EI9B`H(6ES9&EG:70H*'5N<VEG;F5D
M(&-H87(I*F)U9BDI"D!`("TS,S<L-B`K,S8P+#(S($!`"B`)"0D)<F5T=7)N
M(#`["B`*(`D)"71M+3YT;5]Y96%R(#T@:3L**PHK"0D):68@*"IB=68@(3T@
M,"`F)B!I<W-P86-E*"AU;G-I9VYE9"!C:&%R*2IB=68I*0HK"0D)"7=H:6QE
M("@J<'1R("$](#`@)B8@(6ES<W!A8V4H*'5N<VEG;F5D(&-H87(I*G!T<BDI
M"BL)"0D)"7!T<BLK.PHK"0D)8G)E86L["BL**PD)8V%S92`G52<Z"BL)"6-A
M<V4@)U<G.@HK"0D):68@*"%I<V1I9VET*"AU;G-I9VYE9"!C:&%R*2IB=68I
M*0HK"0D)"7)E='5R;B`P.PHK"BL)"0EF;W(@*&D@/2`P.R`J8G5F("$](#`@
M)B8@:7-D:6=I="@H=6YS:6=N960@8VAA<BDJ8G5F*3L@8G5F*RLI('L**PD)
M"0EI("H](#$P.PHK"0D)"6D@*ST@*F)U9B`M("<P)SL**PD)"7T**PD)"6EF
M("AI(#X@-3,I"BL)"0D)<F5T=7)N(#`["B`*(`D)"6EF("@J8G5F("$](#`@
M)B8@:7-S<&%C92@H=6YS:6=N960@8VAA<BDJ8G5F*2D*(`D)"0EW:&EL92`H
L*G!T<B`A/2`P("8F("%I<W-P86-E*"AU;G-I9VYE9"!C:&%R*2IP='(I*0HH
`
end


>Release-Note:
>Audit-Trail:

From: Sheldon Hearn <sheldonh@uunet.co.za>
To: tadf@kt.rim.or.jp
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: bin/10131: bug in strptime(3) 
Date: Tue, 22 Jun 1999 14:45:36 +0200

 For a patch this small, it's probably safe to include it directly,
 rather than uuencoding it.
 
 I've attached a plaintext copy here so that it gets into the PR as
 feedback. Note that the last hunk of the diff applies 2 lines offset. Be
 sure to send feedback if this diff is not being applied to CURRENT
 source (rev 1.6) as intended.
 
 Ciao,
 Sheldon.
 
 --- strptime.c.orig	Sun Sep 13 07:20:40 1998
 +++ strptime.c	Mon Feb 15 00:34:16 1999
 @@ -159,10 +159,10 @@
  				i *= 10;
  				i += *buf - '0';
  			}
 -			if (i > 365)
 +			if (i < 1 || i > 366)
  				return 0;
  
 -			tm->tm_yday = i;
 +			tm->tm_yday = i - 1;
  			break;
  
  		case 'M':
 @@ -177,8 +177,13 @@
  				i *= 10;
  				i += *buf - '0';
  			}
 -			if (i > 59)
 -				return 0;
 +			if (c == 'M') {
 +				if (i > 59)
 +					return 0;
 +			} else {
 +				if (i > 60)
 +					return 0;
 +			}
  
  			if (c == 'M')
  				tm->tm_min = i;
 @@ -259,6 +264,24 @@
  			buf += len;
  			break;
  
 +		case 'w':
 +			if (!isdigit((unsigned char)*buf))
 +				return 0;
 +
 +			for (i = 0; *buf != 0 && isdigit((unsigned char)*buf); buf++) {
 +				i *= 10;
 +				i += *buf - '0';
 +			}
 +			if (i > 6)
 +				return 0;
 +
 +			tm->tm_wday = i;
 +
 +			if (*buf != 0 && isspace((unsigned char)*buf))
 +				while (*ptr != 0 && !isspace((unsigned char)*ptr))
 +					ptr++;
 +			break;
 +
  		case 'd':
  		case 'e':
  			if (!isdigit((unsigned char)*buf))
 @@ -337,6 +360,23 @@
  				return 0;
  
  			tm->tm_year = i;
 +
 +			if (*buf != 0 && isspace((unsigned char)*buf))
 +				while (*ptr != 0 && !isspace((unsigned char)*ptr))
 +					ptr++;
 +			break;
 +
 +		case 'U':
 +		case 'W':
 +			if (!isdigit((unsigned char)*buf))
 +				return 0;
 +
 +			for (i = 0; *buf != 0 && isdigit((unsigned char)*buf); buf++) {
 +				i *= 10;
 +				i += *buf - '0';
 +			}
 +			if (i > 53)
 +				return 0;
  
  			if (*buf != 0 && isspace((unsigned char)*buf))
  				while (*ptr != 0 && !isspace((unsigned char)*ptr))
 
Responsible-Changed-From-To: freebsd-bugs->n_hibma 
Responsible-Changed-By: n_hibma 
Responsible-Changed-When: Fri Jul 16 02:11:28 PDT 1999 
Responsible-Changed-Why:  
Make sure I don't forget to handle this one at a later stage. 
State-Changed-From-To: open->feedback 
State-Changed-By: n_hibma 
State-Changed-When: Fri Jul 16 02:12:04 PDT 1999 
State-Changed-Why:  
Requested feedback from the originator of the function. 

From: Nick Hibma <nick.hibma@jrc.it>
To: Kevin Ruddy <kevin.ruddy@powerdog.com>
Cc: freebsd-gnats-submit@freebsd.org, tadf@kt.rim.or.jp
Subject: Re: bin/10131: bug in strptime(3)
Date: Fri, 16 Jul 1999 11:10:57 +0200 (MET DST)

 In our bug database we have a Problem Report on strptime. You might be
 interested in seeing the patch. It is online available at
 
 	http://www.freebsd.org/cgi/query-pr.cgi?pr=10131
 
 
 Synopsis:
 
 %j should be 1-366, and map to 0-355 in tm_yday.
 %S should be 0-60.
 %w, %U and %W added.
 
 
 Please let us know if we are out of date with our version of strptime.
 
 
 For your reference, I got this e-mail address from the copyright header
 in the file strptime.c. The version it mentions there is
 
 #ifdef LIBC_RCS
 static const char rcsid[] =
         "$Id: strptime.c,v 1.4.2.1 1999/04/30 06:01:45 wes Exp $";
 #endif
 
 #ifndef lint
 #ifndef NOID
 static char copyright[] =
 "@(#) Copyright (c) 1994 Powerdog Industries.  All rights reserved.";
 static char sccsid[] = "@(#)strptime.c  0.1 (Powerdog) 94/03/27";
 #endif /* !defined NOID */
 #endif /* not lint */
 
 
 
 Regards,
 
 Nick
 
 -- 
 Paranoid:
    perl -e 'use strict;' -e ...
 
 ISIS/STA, T.P.270, Joint Research Centre, 21020 Ispra, Italy
 
 

From: Sheldon Hearn <sheldonh@uunet.co.za>
To: Nick Hibma <n_hibma@webweaving.org>
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: bin/10131: bug in strptime(3) 
Date: Wed, 10 Nov 1999 12:13:58 +0200

 On Sat, 11 Sep 1999 00:19:35 +0200, Nick Hibma wrote:
 
 > I'm extremely busy at the moment (with FreeBSD Con coming up), could you
 > do the honours?
 
 I've found a copy of strptime-1.0 and would like to upgrade ours to that
 version. Wotcha think? :-)
 
 Ciao,
 Sheldon.
 

From: Sheldon Hearn <sheldonh@uunet.co.za>
To: Nick Hibma <n_hibma@webweaving.org>
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: bin/10131: bug in strptime(3) 
Date: Wed, 10 Nov 1999 12:25:12 +0200

 On Wed, 10 Nov 1999 12:13:58 +0200, Sheldon Hearn wrote:
 
 > I've found a copy of strptime-1.0 and would like to upgrade ours to that
 > version. Wotcha think? :-)
 
 Bleh, nevermind.  After inspection, I've found that strptime-1.0 offers
 noting over what we have already and still contains the bugs mentioned
 on the PR.
 
 So I'm working on it.  I'm checking what the submitter sent against what
 NetBSD have done.
 
 Ciao,
 Sheldon.
 
Responsible-Changed-From-To: n_hibma->sheldonh 
Responsible-Changed-By: n_hibma 
Responsible-Changed-When: Wed Nov 10 02:52:05 PST 1999 
Responsible-Changed-Why:  
He said he would do it! Honest! I can prove it. 

From: Sheldon Hearn <sheldonh@uunet.co.za>
To: tadf@kt.rim.or.jp
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: bin/10131: bug in strptime(3) 
Date: Wed, 10 Nov 1999 14:55:58 +0200

 Okay, here's a modified version of your submission.  It features an
 order change in the switch construct, a comment stolen from NetBSD for
 the %U and %W cases and deals with the conditional range checking for %M
 and %S slightly differently.
 
 There's been more than enough time for people to object to the change,
 so now it's just a matter of giving a day or so for possible style
 complaints.
 
 Ciao,
 Sheldon.
 
 Index: strptime.c
 ===================================================================
 RCS file: /home/ncvs/src/lib/libc/stdtime/strptime.c,v
 retrieving revision 1.10
 diff -u -d -r1.10 strptime.c
 --- strptime.c	1999/11/04 04:40:56	1.10
 +++ strptime.c	1999/11/10 10:43:43
 @@ -171,10 +171,10 @@
  				i *= 10;
  				i += *buf - '0';
  			}
 -			if (i > 365)
 +			if (i < 1 || i > 366)
  				return 0;
  
 -			tm->tm_yday = i;
 +			tm->tm_yday = i - 1;
  			break;
  
  		case 'M':
 @@ -189,13 +189,16 @@
  				i *= 10;
  				i += *buf - '0';
  			}
 -			if (i > 59)
 -				return 0;
  
 -			if (c == 'M')
 +			if (c == 'M') {
 +				if (i > 59)
 +					return 0;
  				tm->tm_min = i;
 -			else
 +			} else {
 +				if (i > 60)
 +					return 0;
  				tm->tm_sec = i;
 +			}
  
  			if (*buf != 0 && isspace((unsigned char)*buf))
  				while (*ptr != 0 && !isspace((unsigned char)*ptr))
 @@ -269,6 +272,47 @@
  
  			tm->tm_wday = i;
  			buf += len;
 +			break;
 +
 +		case 'U':
 +		case 'W':
 +			/*
 +			 * XXX This is bogus, as we can not assume any valid
 +			 * information present in the tm structure at this
 +			 * point to calculate a real value, so just check the
 +			 * range for now.
 +			 */
 +			if (!isdigit((unsigned char)*buf))
 +				return 0;
 +
 +			for (i = 0; *buf != 0 && isdigit((unsigned char)*buf); buf++) {
 +				i *= 10;
 +				i += *buf - '0';
 +			}
 +			if (i > 53)
 +				return 0;
 +
 +			if (*buf != 0 && isspace((unsigned char)*buf))
 +				while (*ptr != 0 && !isspace((unsigned char)*ptr))
 +					ptr++;
 +			break;
 +
 +		case 'w':
 +			if (!isdigit((unsigned char)*buf))
 +				return 0;
 +
 +			for (i = 0; *buf != 0 && isdigit((unsigned char)*buf); buf++) {
 +				i *= 10;
 +				i += *buf - '0';
 +			}
 +			if (i > 6)
 +				return 0;
 +
 +			tm->tm_wday = i;
 +
 +			if (*buf != 0 && isspace((unsigned char)*buf))
 +				while (*ptr != 0 && !isspace((unsigned char)*ptr))
 +					ptr++;
  			break;
  
  		case 'd':
 
State-Changed-From-To: feedback->suspended 
State-Changed-By: sheldonh 
State-Changed-When: Wed Nov 10 06:41:08 PST 1999 
State-Changed-Why:  
Committed in strptime.c rev 1.11, waiting for MFC before closing. 
State-Changed-From-To: suspended->closed 
State-Changed-By: sheldonh 
State-Changed-When: Thu Dec 9 01:00:18 PST 1999 
State-Changed-Why:  
Finally fixed for RELENG_3 in rev 1.4.2.4 of strptime.c . 
Thanks for your report and your patience. :-) 
>Unformatted:
