From: Daniel Stenberg Date: Sun, 31 Aug 2025 21:21:43 +0000 (+0200) Subject: tool_filetime: accept setting negative filetime X-Git-Tag: curl-8_16_0~56 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=54f1ef05d672453d75a5fc60f7658eaa835ce5cc;p=thirdparty%2Fcurl.git tool_filetime: accept setting negative filetime This allows --remote-time to set dates before 1970. Due to a minor omission in the API, it will still avoid setting the time if it is indeed exactly epoch 0 (jan 1 1970). Verified by test 762 Fixes #18424 Reported-by: Terence Eden Closes #18443 --- diff --git a/src/tool_filetime.c b/src/tool_filetime.c index 8907bcda61..424b8cc7ea 100644 --- a/src/tool_filetime.c +++ b/src/tool_filetime.c @@ -88,7 +88,7 @@ int getfiletime(const char *filename, curl_off_t *stamp) #if defined(HAVE_UTIME) || defined(HAVE_UTIMES) || defined(_WIN32) void setfiletime(curl_off_t filetime, const char *filename) { - if(filetime >= 0) { + if(filetime) { /* Windows utime() may attempt to adjust the Unix GMT file time by a daylight saving time offset and since it is GMT that is bad behavior. When we have access to a 64-bit type we can bypass utime and set the times directly. */ diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am index f8470c554a..9d1fcbb759 100644 --- a/tests/data/Makefile.am +++ b/tests/data/Makefile.am @@ -108,7 +108,8 @@ test718 test719 test720 test721 test722 test723 test724 test725 test726 \ test727 test728 test729 test730 test731 test732 test733 test734 test735 \ test736 test737 test738 test739 test740 test741 test742 test743 test744 \ test745 test746 test747 test748 test749 test750 test751 test752 test753 \ -test754 test755 test756 test757 test758 test759 test760 test761 \ +test754 test755 test756 test757 test758 test759 test760 test761 test762 \ +\ test780 test781 test782 test783 test784 test785 test786 test787 test788 \ test789 test790 test791 test792 test793 test794 test795 test796 test797 \ \ diff --git a/tests/data/test762 b/tests/data/test762 new file mode 100644 index 0000000000..62ce9e6325 --- /dev/null +++ b/tests/data/test762 @@ -0,0 +1,56 @@ + + + +HTTP +HTTP GET +--remote-time + + + +# + + +HTTP/1.1 200 OK +Date: Tue, 09 Nov 2010 14:49:00 GMT +Server: test-server/fake +Last-Modified: Wed, 09 Oct 1940 16:45:49 +0100 +Content-Length: 6 +Connection: close + +12345 + + + +# +# Client-side + + +http + + +HTTP GET with --remote-time with file date from 1940 + + +http://%HOSTIP:%HTTPPORT/%TESTNUMBER -O --remote-time --output-dir %LOGDIR + + + +# +# Verify data after the test has been "shot" + + +GET /%TESTNUMBER HTTP/1.1 +Host: %HOSTIP:%HTTPPORT +User-Agent: curl/%VERSION +Accept: */* + + + +12345 + +# Modify: 1940-10-09 16:45:49.000000000 +0100 + +%PERL -e 'exit((stat("%LOGDIR/%TESTNUMBER"))[9] != -922349651)' + + +