Module Name: src Committed By: lukem Date: Thu Mar 4 21:40:53 UTC 2010
Modified Files: src/usr.bin/ftp: extern.h fetch.c util.c Log Message: Parse HTTP 'Date' entries in the `C' locale rather than the user's. Fix from [bin/42917] (with minor changes), from KAMADA Ken'ichi. To generate a diff of this commit: cvs rdiff -u -r1.77 -r1.78 src/usr.bin/ftp/extern.h cvs rdiff -u -r1.191 -r1.192 src/usr.bin/ftp/fetch.c cvs rdiff -u -r1.152 -r1.153 src/usr.bin/ftp/util.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/ftp/extern.h diff -u src/usr.bin/ftp/extern.h:1.77 src/usr.bin/ftp/extern.h:1.78 --- src/usr.bin/ftp/extern.h:1.77 Mon Jul 13 19:05:41 2009 +++ src/usr.bin/ftp/extern.h Thu Mar 4 21:40:53 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: extern.h,v 1.77 2009/07/13 19:05:41 roy Exp $ */ +/* $NetBSD: extern.h,v 1.78 2010/03/04 21:40:53 lukem Exp $ */ /*- * Copyright (c) 1996-2009 The NetBSD Foundation, Inc. @@ -166,6 +166,7 @@ void opts(int, char **); void newer(int, char **); void page(int, char **); +const char *parse_rfc2616time(struct tm *, const char *); int parserate(int, char **, int); char *prompt(void); void proxabort(int); Index: src/usr.bin/ftp/fetch.c diff -u src/usr.bin/ftp/fetch.c:1.191 src/usr.bin/ftp/fetch.c:1.192 --- src/usr.bin/ftp/fetch.c:1.191 Mon Aug 17 09:08:16 2009 +++ src/usr.bin/ftp/fetch.c Thu Mar 4 21:40:53 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: fetch.c,v 1.191 2009/08/17 09:08:16 christos Exp $ */ +/* $NetBSD: fetch.c,v 1.192 2010/03/04 21:40:53 lukem Exp $ */ /*- * Copyright (c) 1997-2009 The NetBSD Foundation, Inc. @@ -34,7 +34,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: fetch.c,v 1.191 2009/08/17 09:08:16 christos Exp $"); +__RCSID("$NetBSD: fetch.c,v 1.192 2010/03/04 21:40:53 lukem Exp $"); #endif /* not lint */ /* @@ -934,28 +934,18 @@ } else if (match_token(&cp, "Last-Modified:")) { struct tm parsed; - char *t; + const char *t; memset(&parsed, 0, sizeof(parsed)); - /* RFC1123 */ - if ((t = strptime(cp, - "%a, %d %b %Y %H:%M:%S GMT", - &parsed)) - /* RFC0850 */ - || (t = strptime(cp, - "%a, %d-%b-%y %H:%M:%S GMT", - &parsed)) - /* asctime */ - || (t = strptime(cp, - "%a, %b %d %H:%M:%S %Y", - &parsed))) { + t = parse_rfc2616time(&parsed, cp); + if (t != NULL) { parsed.tm_isdst = -1; if (*t == '\0') mtime = timegm(&parsed); #ifndef NO_DEBUG if (ftp_debug && mtime != -1) { fprintf(ttyout, - "parsed date as: %s", + "parsed time as: %s", rfc2822time(localtime(&mtime))); } #endif Index: src/usr.bin/ftp/util.c diff -u src/usr.bin/ftp/util.c:1.152 src/usr.bin/ftp/util.c:1.153 --- src/usr.bin/ftp/util.c:1.152 Mon Jul 13 19:05:41 2009 +++ src/usr.bin/ftp/util.c Thu Mar 4 21:40:53 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: util.c,v 1.152 2009/07/13 19:05:41 roy Exp $ */ +/* $NetBSD: util.c,v 1.153 2010/03/04 21:40:53 lukem Exp $ */ /*- * Copyright (c) 1997-2009 The NetBSD Foundation, Inc. @@ -64,7 +64,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: util.c,v 1.152 2009/07/13 19:05:41 roy Exp $"); +__RCSID("$NetBSD: util.c,v 1.153 2010/03/04 21:40:53 lukem Exp $"); #endif /* not lint */ /* @@ -85,6 +85,7 @@ #include <signal.h> #include <libgen.h> #include <limits.h> +#include <locale.h> #include <netdb.h> #include <stdio.h> #include <stdlib.h> @@ -756,7 +757,7 @@ else goto cleanup_parse_time; } else { - DPRINTF("remotemodtime: parsed date `%s' as " LLF + DPRINTF("remotemodtime: parsed time `%s' as " LLF ", %s", timestr, (LLT)rtime, rfc2822time(localtime(&rtime))); @@ -792,6 +793,32 @@ } /* + * Parse HTTP-date as per RFC 2616. + * Return a pointer to the next character of the consumed date string, + * or NULL if failed. + */ +const char * +parse_rfc2616time(struct tm *parsed, const char *httpdate) +{ + const char *t; + const char *curlocale; + + /* The representation of %a depends on the current locale. */ + curlocale = setlocale(LC_TIME, NULL); + (void)setlocale(LC_TIME, "C"); + /* RFC1123 */ + if ((t = strptime(httpdate, "%a, %d %b %Y %H:%M:%S GMT", parsed)) || + /* RFC0850 */ + (t = strptime(httpdate, "%a, %d-%b-%y %H:%M:%S GMT", parsed)) || + /* asctime */ + (t = strptime(httpdate, "%a, %b %d %H:%M:%S %Y", parsed))) { + ; /* do nothing */ + } + (void)setlocale(LC_TIME, curlocale); + return t; +} + +/* * Update global `localcwd', which contains the state of the local cwd */ void