Re: gmtime_r bug in High Sierra?
site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=7/VIyqKTXSDEjBLEv/CkZ/kUE27sOEJz+Y06XPDP9eY=; b=mzVl4CL78ElHt/GTrMsVtL1XuiceIGFpc3j6TCUlc7dVHjLQpzqXF1/LzFGJMRiS6f O2l5jStcH2Oxl6eXJqTG4R2jHgF0Jt6WUpb9TXiprxHWpXJtKom6ZXn6I5NKIsb2e4KU swIa2rm6W/jfUbd9X8OW56aMZtlaueSFzPAdioeg+43LvgV/H7V1OYp1Yn1Cf4AnErF7 ZyoRA8XIY4u9SHLqjwEjMNs6Yyko6OnZj6Jnso5Mq/3XUH0te2huc8Qo8ZiI9xA6GQzQ FnD4nI33JgFBHOScAKCPdloOZe8HIJbhyin1pj01QdPMMuvqJsvwz9x9NksVgZiIrJ0n ujnA== With this comment, I'll cross-post this to the filesystem-dev list, as this could be a bug in the APFS code, making this a bit urgent with the imminent release of 10.13 But it could also be that there's a new(?) flag somewhere that you need to test in order to tell whether the values are in seconds or microseconds. Maybe someone on the filesystem list could clarify this? Thomas On Sun, Sep 10, 2017 at 8:13 AM, Stephane Sudre <dev.iceberg@gmail.com> wrote:
Very interesting. Thanks.
As a matter of fact, the code (and the value sent to gmtime_r) are extracted from the xar Apple source code (and when it's run on High Sierra):
https://opensource.apple.com/source/xar/xar-357/xar/lib/ darwinattr.c.auto.html
stragglers_archive
So now, it looks like the problem is earlier in the code and it comes from the value returned by getattrlist(2).
If I run the code (*) for a file on a HFS+ volume, the value looks correct. If I run the code for a file on a APFS volume, the value looks incorrect.
* In conditions specific to the code using the xar code, which is a launchd daemon and playing with a file that was very recently created.
On Sun, Sep 10, 2017 at 3:23 AM, Stephen J. Butler <stephen.butler@gmail.com> wrote:
It's not a bug IMHO. The problem is that you don't check the return value of gmtime_r(). If you did, you'd see that the result is NULL (which means the function failed) and so you shouldn't use any of the results (they're undefined).
#include <unistd.h> #include <time.h> #include <string.h> #include <stdio.h>
int main(int argc, const char * argv[]) {
char tmpc[128]; struct tm tm;
memset(tmpc, 0, sizeof(tmpc));
__darwin_time_t tValue=2914986787602432000;
if (gmtime_r(&tValue, &tm)) { strftime(tmpc, sizeof(tmpc), "%FT%T", &tm);
printf("time: %s\n",tmpc);
printf("-----------------\n"); }
struct tm tm2; tm2.tm_mon=10240;
memset(tmpc, 0, sizeof(tmpc));
tValue=2914986787602432000;
if (gmtime_r(&tValue, &tm2)) { strftime(tmpc, sizeof(tmpc), "%FT%T", &tm2);
printf("time: %s\n",tmpc); }
return 0; }
But also here, the number you're providing to tValue looks a lot like nanosecond time stamp, and gmtime_r() expects seconds. If you correct that, then you get:
time: 2062-05-16T06:33:07 ----------------- time: 2062-05-16T06:33:07
On Sat, Sep 9, 2017 at 5:51 PM, Stephane Sudre <dev.iceberg@gmail.com> wrote:
Maybe I'm missing something (regarding the tm var) but shouldn't all the struct tm fields be correctly set by gmtime_r?
#include <unistd.h> #include <time.h> #include <string.h> #include <stdio.h>
int main(int argc, const char * argv[]) {
char tmpc[128]; struct tm tm;
memset(tmpc, 0, sizeof(tmpc));
__darwin_time_t tValue=2914986787602432000;
gmtime_r(&tValue, &tm); strftime(tmpc, sizeof(tmpc), "%FT%T", &tm);
printf("time: %s\n",tmpc);
printf("-----------------\n");
struct tm tm2; tm2.tm_mon=10240;
memset(tmpc, 0, sizeof(tmpc));
tValue=2914986787602432000;
gmtime_r(&tValue, &tm2); strftime(tmpc, sizeof(tmpc), "%FT%T", &tm2);
printf("time: %s\n",tmpc);
return 0; }
=>
time: 1900-01-00T18:40:00 ----------------- time: 1900-10241-00T18:40:00
_______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.app... This email sent to site_archiver@lists.apple.com
participants (1)
-
Thomas Tempelmann