[OpenAFS-devel] Re: [OpenAFS] vos: failed to parse date...

Jeffrey Hutzelman jhutz@cmu.edu
Fri, 31 Mar 2006 16:19:13 -0500


On Friday, March 31, 2006 09:49:24 AM -0500 Jim Rees <rees@umich.edu> wrote:

>      code =
>  	sscanf(adate, "%d / %d / %d %d : %d : %d%1s", &month, &day2, &year,
> @@ -528,13 +529,28 @@
>  		   &hour, &min, &c[0]);

I still think we should do _something_ about the mismatched format string 
and arguments here.  Either nuke the last %d, or add another input argument 
for seconds, but as it stands now, this code is wrong and may crash.



> +    /* New ISO 8601 (subset) format */
> +
> +    if (code < 0) {
> +	hour = min = sec = 0;
> +	code =
> +	    sscanf(adate, "%d-%d-%d %d:%d:%d%1s", &year, &month, &day2,
> +		   &hour, &min, &sec, c);

Your last patch had whitespace in the sscanf format string, like the one 
above.  Did you intend to remove that?

> +	if (code != 3 && code != 5 && code != 6)
> +	    code = -1;

OK; now it has the same level of validation as the old code.  We might want 
to consider making it more strict at some point; see my previous message. 
But I don't consider the lack of additional strictness a showstopper.


> +    afs_int32 code;
> +    long l;
> +    char c[2];
> +
> +    if (sscanf(adate, "%ld%1s", &l, c) == 1)
> +	*aint32 = l;
> +    else {
> +	/* parse the date into a ktime_date structure */
> +	code = ktime_ParseDate(adate, &tdate);
> +	if (code)
> +	    return code;		/* failed to parse */
> +	code = ktime_InterpretDate(&tdate);	/* interpret as seconds since 1970
> */ +	*aint32 = code;		/* return it */
> +    }

Good...


-- Jeff