]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tool_filetime: accept setting negative filetime
authorDaniel Stenberg <daniel@haxx.se>
Sun, 31 Aug 2025 21:21:43 +0000 (23:21 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 1 Sep 2025 06:51:36 +0000 (08:51 +0200)
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

src/tool_filetime.c
tests/data/Makefile.am
tests/data/test762 [new file with mode: 0644]

index 8907bcda618feab684390a924729e7d149751fdd..424b8cc7ea9f3db318ff330b0f61b4f2527f4dd0 100644 (file)
@@ -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. */
index f8470c554a2cfedfe2fdb1a4ca5e1825fd41b2de..9d1fcbb759afc33cb3c023f921ce201b8c01654b 100644 (file)
@@ -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 (file)
index 0000000..62ce9e6
--- /dev/null
@@ -0,0 +1,56 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+--remote-time
+</keywords>
+</info>
+
+#
+<reply>
+<data nocheck="yes">
+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
+</data>
+</reply>
+
+#
+# Client-side
+<client>
+<server>
+http
+</server>
+<name>
+HTTP GET with --remote-time with file date from 1940
+</name>
+<command option="no-output,no-include">
+http://%HOSTIP:%HTTPPORT/%TESTNUMBER -O --remote-time --output-dir %LOGDIR
+</command>
+</client>
+
+#
+# Verify data after the test has been "shot"
+<verify>
+<protocol>
+GET /%TESTNUMBER HTTP/1.1\r
+Host: %HOSTIP:%HTTPPORT\r
+User-Agent: curl/%VERSION\r
+Accept: */*\r
+\r
+</protocol>
+<file name="%LOGDIR/%TESTNUMBER">
+12345
+</file>
+# Modify: 1940-10-09 16:45:49.000000000 +0100
+<postcheck>
+%PERL -e 'exit((stat("%LOGDIR/%TESTNUMBER"))[9] != -922349651)'
+</postcheck>
+</verify>
+</testcase>