From nobody Wed Oct 19 17:04:17 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4MsxsZ0Q4Sz4gQv5; Wed, 19 Oct 2022 17:04:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MsxsY72Wcz3gHM; Wed, 19 Oct 2022 17:04:17 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666199058; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=i31s3VbhKhu9WXiwhkGmUbb6OjZUToaRckjpeSSf+Fc=; b=QLWszifTL2yB4n1w77aKb4bXDNutDLB3CFFG1WqjiiUabWXveAjBP2IMT66UHrIaA646YO 8Y5FynEIF0f7APe8CXL7APrem6EgKVObXiV3vaCvPVEa/cmIRfDb5sWmg3XC8xs4EKLg9U aPDKSKdVKpUc3imPlIbUuwynPR2CTCEY86dpzCrkSp4coq5HUKQsToSqailtt+4/5fU1Q+ +HnIZCEvcVh6fb8r4z2wCCbReirtQEeHSGF7EA/3ZUKTdQinjMaTPaaTl6WwmIyzQWm7C2 Q1t/gmMRv6YM33eP3tH/A2aHqHxpVArDNtXZWEmQ2fSW4v2FH2gcCj4iC+RDxw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4MsxsY6513zbXf; Wed, 19 Oct 2022 17:04:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 29JH4Hqe049339; Wed, 19 Oct 2022 17:04:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 29JH4HxM049338; Wed, 19 Oct 2022 17:04:17 GMT (envelope-from git) Date: Wed, 19 Oct 2022 17:04:17 GMT Message-Id: <202210191704.29JH4HxM049338@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Dag-Erling=20Sm=C3=B8rgrav?= Subject: git: d05e43bc0d57 - main - pax: update date parsing code (from OpenBSD) List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d05e43bc0d5705919d057793aaa3e6d3df65f815 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666199058; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=i31s3VbhKhu9WXiwhkGmUbb6OjZUToaRckjpeSSf+Fc=; b=B7qKFaZpH7XIz9Wx+y0LzEOeC0LhmG6voRt3biNERvMgW3R4lAQKPut9dITqU8QhIv92nm 77B4amlOzGbFvR05jCJ6B30/LQpHnjWTklX4hhlA1aCIqHOtxxI5YQfqk3ANIYRVFSWWbS Us2eLovLgL3TDF0dlFsegq3Kin7+rCl1KTtkpXNNG5N04aKBvm0W22kjdbGvaijVXBN5nk Z/FlpgOY+1+ERqAKphvWxn3AIEaaE2sudt1EjDv4BGPa84ptTqspORYrsCqEPRt3WkG+v8 BP0nh5I7bsezM8xT5MVn0YvKT/hlOzD6XZMhpY9DTOHYJ/44ACDVHqx4bRDoLw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1666199058; a=rsa-sha256; cv=none; b=WbUg0wL8Ktwe5Cfh8+/JU0yKjj3v/5YDq25wLbD2a8En9wBHrqGiEfH0joG+1NLrhgOIw1 0qzyAfqDcdKmFPqxCE4dfvvrxEEKmoYu02pnU/CpUiOdWNH4anG3KF+rDArEbC/vNqhrm1 znkQl6j0kIRXGepb85q0gmIEaC35093aZVKU/hRbkkMWHi5vEZjAYEud2OSJm758NtCOHj fwmVROnsOzjoC864HubHEs4eOZabMIdVQezzRzPDxkq7EBN6PI3WSfbX85BSP3h/q45wWy xDgGMMsypX67hUadGP2dklxPl4vqtNwjmghBCbk/RHvx7lLke3sJ/xE2Pv1NcQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=d05e43bc0d5705919d057793aaa3e6d3df65f815 commit d05e43bc0d5705919d057793aaa3e6d3df65f815 Author: Dag-Erling Smørgrav AuthorDate: 2022-10-19 17:02:45 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2022-10-19 17:02:45 +0000 pax: update date parsing code (from OpenBSD) Sponsored by: Klara, Inc. MFC after: 1 week --- bin/pax/pax.1 | 25 +++++++----- bin/pax/sel_subs.c | 116 +++++++++++++++++++++++++++++------------------------ bin/pax/sel_subs.h | 2 +- 3 files changed, 78 insertions(+), 65 deletions(-) diff --git a/bin/pax/pax.1 b/bin/pax/pax.1 index abfbacee78b3..b503e1562f8a 100644 --- a/bin/pax/pax.1 +++ b/bin/pax/pax.1 @@ -33,7 +33,7 @@ .\" @(#)pax.1 8.4 (Berkeley) 4/18/94 .\" $FreeBSD$ .\" -.Dd December 29, 2018 +.Dd October 19, 2022 .Dt PAX 1 .Os .Sh NAME @@ -933,28 +933,31 @@ changed during a specified time range will be archived). A time range is made up of six different fields and each field must contain two digits. The format is: -.Dl [yy[mm[dd[hh]]]]mm[.ss] +.Pp +.Dl [[[[[cc]yy]mm]dd]HH]MM[.SS] +.Pp Where -.Cm yy +.Ar cc +is the first two digits of the year (the century), +.Ar yy is the last two digits of the year, the first -.Cm mm +.Ar mm is the month (from 01 to 12), -.Cm dd +.Ar dd is the day of the month (from 01 to 31), -.Cm hh +.Ar HH is the hour of the day (from 00 to 23), -the second -.Cm mm +.Ar MM is the minute (from 00 to 59), and -.Cm ss +.Ar SS is the seconds (from 00 to 59). The minute field -.Cm mm +.Ar MM is required, while the other fields are optional and must be added in the following order: -.Dl Cm hh , dd , mm , yy . +.Ar HH , dd , mm , yy , cc . The .Cm ss field may be added independently of the other fields. diff --git a/bin/pax/sel_subs.c b/bin/pax/sel_subs.c index 12975f21946f..7ef5bec523a5 100644 --- a/bin/pax/sel_subs.c +++ b/bin/pax/sel_subs.c @@ -44,17 +44,20 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include + +#include #include +#include #include +#include #include #include -#include + #include "pax.h" #include "sel_subs.h" #include "extern.h" -static int str_sec(char *, time_t *); +static int str_sec(const char *, time_t *); static int usr_match(ARCHD *); static int grp_match(ARCHD *); static int trng_match(ARCHD *); @@ -309,7 +312,7 @@ grp_match(ARCHD *arcn) * trng_add() * add a time range match to the time range list. * This is a non-standard pax option. Lower and upper ranges are in the - * format: [yy[mm[dd[hh]]]]mm[.ss] and are comma separated. + * format: [[[[[cc]yy]mm]dd]HH]MM[.SS] and are comma separated. * Time ranges are based on current time, so 1234 would specify a time of * 12:34 today. * Return: @@ -446,7 +449,7 @@ trng_add(char *str) return(0); out: - paxwarn(1, "Time range format is: [yy[mm[dd[hh]]]]mm[.ss][/[c][m]]"); + paxwarn(1, "Time range format is: [[[[[cc]yy]mm]dd]HH]MM[.SS][/[c][m]]"); return(-1); } @@ -520,80 +523,87 @@ trng_match(ARCHD *arcn) /* * str_sec() - * Convert a time string in the format of [[[[yy[mm[dd[hh]mm[.ss] to gmt - * seconds. Tval already has current time loaded into it at entry. + * Convert a time string in the format of [[[[[cc]yy]mm]dd]HH]MM[.SS] to + * seconds UTC. Tval already has current time loaded into it at entry. * Return: * 0 if converted ok, -1 otherwise */ static int -str_sec(char *str, time_t *tval) +str_sec(const char *p, time_t *tval) { struct tm *lt; - char *dot = NULL; + const char *dot, *t; + size_t len; + int bigyear; + int yearset; + + yearset = 0; + len = strlen(p); + + for (t = p, dot = NULL; *t; ++t) { + if (isdigit((unsigned char)*t)) + continue; + if (*t == '.' && dot == NULL) { + dot = t; + continue; + } + return(-1); + } lt = localtime(tval); - if ((dot = strchr(str, '.')) != NULL) { - /* - * seconds (.ss) - */ - *dot++ = '\0'; - if (strlen(dot) != 2) + + if (dot != NULL) { /* .SS */ + if (strlen(++dot) != 2) return(-1); - if ((lt->tm_sec = ATOI2(dot)) > 61) + lt->tm_sec = ATOI2(dot); + if (lt->tm_sec > 61) return(-1); + len -= 3; } else lt->tm_sec = 0; - switch (strlen(str)) { - case 10: - /* - * year (yy) - * watch out for year 2000 - */ - if ((lt->tm_year = ATOI2(str)) < 69) - lt->tm_year += 100; - str += 2; + switch (len) { + case 12: /* cc */ + bigyear = ATOI2(p); + lt->tm_year = (bigyear * 100) - 1900; + yearset = 1; /* FALLTHROUGH */ - case 8: - /* - * month (mm) - * watch out months are from 0 - 11 internally - */ - if ((lt->tm_mon = ATOI2(str)) > 12) + case 10: /* yy */ + if (yearset) { + lt->tm_year += ATOI2(p); + } else { + lt->tm_year = ATOI2(p); + if (lt->tm_year < 69) /* hack for 2000 ;-} */ + lt->tm_year += (2000 - 1900); + } + /* FALLTHROUGH */ + case 8: /* mm */ + lt->tm_mon = ATOI2(p); + if ((lt->tm_mon > 12) || !lt->tm_mon) return(-1); - --lt->tm_mon; - str += 2; + --lt->tm_mon; /* time struct is 0 - 11 */ /* FALLTHROUGH */ - case 6: - /* - * day (dd) - */ - if ((lt->tm_mday = ATOI2(str)) > 31) + case 6: /* dd */ + lt->tm_mday = ATOI2(p); + if ((lt->tm_mday > 31) || !lt->tm_mday) return(-1); - str += 2; /* FALLTHROUGH */ - case 4: - /* - * hour (hh) - */ - if ((lt->tm_hour = ATOI2(str)) > 23) + case 4: /* HH */ + lt->tm_hour = ATOI2(p); + if (lt->tm_hour > 23) return(-1); - str += 2; /* FALLTHROUGH */ - case 2: - /* - * minute (mm) - */ - if ((lt->tm_min = ATOI2(str)) > 59) + case 2: /* MM */ + lt->tm_min = ATOI2(p); + if (lt->tm_min > 59) return(-1); break; default: return(-1); } - /* - * convert broken-down time to GMT clock time seconds - */ + + /* convert broken-down time to UTC clock time seconds */ if ((*tval = mktime(lt)) == -1) return(-1); return(0); diff --git a/bin/pax/sel_subs.h b/bin/pax/sel_subs.h index 7e1ddeedcb87..a628e6981b1a 100644 --- a/bin/pax/sel_subs.h +++ b/bin/pax/sel_subs.h @@ -57,7 +57,7 @@ typedef struct grpt { * data structure for storing user supplied time ranges (-T option) */ -#define ATOI2(s) ((((s)[0] - '0') * 10) + ((s)[1] - '0')) +#define ATOI2(ar) ((ar)[0] - '0') * 10 + ((ar)[1] - '0'); (ar) += 2; typedef struct time_rng { time_t low_time; /* lower inclusive time limit */