From: Ralph Boehme Date: Thu, 13 Nov 2025 17:42:41 +0000 (+0100) Subject: mdssvc: support a wider range of years [0000,9999] in $time.iso X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1b2b08bb7067852ad1bf8847b266baaab06905d7;p=thirdparty%2Fsamba.git mdssvc: support a wider range of years [0000,9999] in $time.iso Most importantly use strtoll to allow negative numbers and use a filed width with %Y in strftime() to parse years with less then four digits. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15947 Signed-off-by: Ralph Boehme Reviewed-by: Douglas Bagnall Autobuild-User(master): Douglas Bagnall Autobuild-Date(master): Wed Nov 19 01:59:34 UTC 2025 on atb-devel-224 --- diff --git a/source3/rpc_server/mdssvc/es_parser.y b/source3/rpc_server/mdssvc/es_parser.y index 1f1c02ba1a5..267bc808091 100644 --- a/source3/rpc_server/mdssvc/es_parser.y +++ b/source3/rpc_server/mdssvc/es_parser.y @@ -494,15 +494,16 @@ static char *map_str(const struct es_attr_map *attr, static char *map_sldate_to_esdate(TALLOC_CTX *mem_ctx, const char *sldate) { + char *endp = NULL; struct tm *tm = NULL; char *esdate = NULL; char buf[21]; size_t len; time_t t; - int error; - t = (time_t)smb_strtoull(sldate, NULL, 10, &error, SMB_STR_STANDARD); - if (error != 0) { + errno = 0; + t = (time_t)strtoll(sldate, &endp, 10); + if (*sldate == '\0' || endp == sldate || *endp != '\0' || errno != 0) { DBG_ERR("smb_strtoull [%s] failed\n", sldate); return NULL; } @@ -515,7 +516,7 @@ static char *map_sldate_to_esdate(TALLOC_CTX *mem_ctx, } len = strftime(buf, sizeof(buf), - "%Y-%m-%dT%H:%M:%SZ", tm); + "%4Y-%m-%dT%H:%M:%SZ", tm); if (len != 20) { DBG_ERR("strftime [%s] failed\n", sldate); return NULL; diff --git a/source3/rpc_server/mdssvc/test_mdsparser_es.c b/source3/rpc_server/mdssvc/test_mdsparser_es.c index 5015de82127..1de8a317930 100644 --- a/source3/rpc_server/mdssvc/test_mdsparser_es.c +++ b/source3/rpc_server/mdssvc/test_mdsparser_es.c @@ -53,6 +53,20 @@ static struct { }, { "kMDItemFSContentChangeDate==$time.iso(2018-10-01T10:00:00Z)", "file.last_modified:2018\\\\-10\\\\-01T10\\\\:00\\\\:00Z" + }, { + "kMDItemFSContentChangeDate==$time.iso(1960-10-01T10:00:00Z)", + "file.last_modified:1960\\\\-10\\\\-01T10\\\\:00\\\\:00Z" +#ifdef __LP64__ + }, { + "kMDItemFSContentChangeDate==$time.iso(1000-10-01T10:00:00Z)", + "file.last_modified:1000\\\\-10\\\\-01T10\\\\:00\\\\:00Z" + }, { + "kMDItemFSContentChangeDate==$time.iso(0000-10-01T10:00:00Z)", + "file.last_modified:0000\\\\-10\\\\-01T10\\\\:00\\\\:00Z" + }, { + "kMDItemFSContentChangeDate==$time.iso(9999-10-01T10:00:00Z)", + "file.last_modified:9999\\\\-10\\\\-01T10\\\\:00\\\\:00Z" +#endif }, { "kMDItemFSContentChangeDate==\"1\"", "file.last_modified:2001\\\\-01\\\\-01T00\\\\:00\\\\:01Z"