]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
ftp: a 550 response to SIZE returns CURLE_REMOTE_FILE_NOT_FOUND
authorDaniel Stenberg <daniel@haxx.se>
Sat, 12 Sep 2020 16:27:08 +0000 (18:27 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 14 Sep 2020 10:53:12 +0000 (12:53 +0200)
This is primarily interesting for cases where CURLOPT_NOBODY is set as
previously curl would not return an error for this case.

MDTM getting 550 now also returns this error (it returned
CURLE_FTP_COULDNT_RETR_FILE before) in order to unify return codes for
missing files across protocols and specific FTP commands.

libcurl already returns error on a 550 as a MDTM response (when
CURLOPT_FILETIME is set). If CURLOPT_NOBODY is not set, an error would
happen subsequently anyway since the RETR command would fail.

Add test 1913 and 1914 to verify. Updated several tests accordingly due
to the updated SIZE behavior.

Reported-by: Tomas Berger
Fixes #5953
Closes #5957

16 files changed:
lib/ftp.c
tests/data/Makefile.inc
tests/data/test1096
tests/data/test118
tests/data/test119
tests/data/test138
tests/data/test1913 [new file with mode: 0644]
tests/data/test1914 [new file with mode: 0644]
tests/data/test235
tests/data/test236
tests/data/test511
tests/data/test533
tests/data/test534
tests/data/test546
tests/libtest/Makefile.inc
tests/libtest/lib1913.c [new file with mode: 0644]

index 9fadac5138145489dea25d5d5ac76aeaf85440f8..d4ecf9a9608347677624bc42acbad5c125129070 100644 (file)
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -2092,7 +2092,7 @@ static CURLcode ftp_state_mdtm_resp(struct connectdata *conn,
     break;
   case 550: /* "No such file or directory" */
     failf(data, "Given file does not exist");
-    result = CURLE_FTP_COULDNT_RETR_FILE;
+    result = CURLE_REMOTE_FILE_NOT_FOUND;
     break;
   }
 
@@ -2272,6 +2272,10 @@ static CURLcode ftp_state_size_resp(struct connectdata *conn,
     (void)curlx_strtoofft(fdigit, NULL, 0, &filesize);
 
   }
+  else if(ftpcode == 550) { /* "No such file or directory" */
+    failf(data, "The file does not exist");
+    return CURLE_REMOTE_FILE_NOT_FOUND;
+  }
 
   if(instate == FTP_SIZE) {
 #ifdef CURL_FTP_HTTPSTYLE_HEAD
index 3832e26b4de80f0c624914daa1b50fb51b4d4b3c..606a6031ac11bb3f8ef9c2295ff3ce1eb2f461e3 100644 (file)
@@ -207,7 +207,7 @@ test1700 test1701 test1702 \
 test1800 test1801 \
 \
                                     test1904 test1905 test1906 test1907 \
-test1908 test1909 test1910 test1911 test1912 \
+test1908 test1909 test1910 test1911 test1912 test1913 test1914 \
 \
 test2000 test2001 test2002 test2003 test2004 test2005 test2006 test2007 \
 test2008 test2009 test2010 test2011 test2012 test2013 test2014 test2015 \
index 30748c1b4e645ab32803ed6bdf6d171a91360e38..a6c32c3a16610072db7ef3dcb0becdfa96551b97 100644 (file)
@@ -11,6 +11,7 @@ FAILURE
 <reply>
 <servercmd>
 REPLY RETR 550 no such file!
+REPLY SIZE 500 command not understood
 </servercmd>
 </reply>
 
index 6cd086ca239b839c9a7d9ee17fad96ea655f03d6..94985e31908a41d3f06a685f35b11a59b8168e6b 100644 (file)
@@ -12,6 +12,7 @@ FAILURE
 <servercmd>
 REPLY RETR 314 bluah you f00l!
 REPLY EPSV 314 bluah you f00l!
+REPLY SIZE 500 command not understood
 </servercmd>
 </reply>
 
index 00a24287b76483aae7766ac7f18a6dd64f633a1f..95d1021ca801b2866060d53cf5f12b6be46d33bd 100644 (file)
@@ -11,6 +11,7 @@ FAILURE
 <reply>
 <servercmd>
 REPLY RETR 314 bluah you f00l!
+REPLY SIZE 500 command not understood
 </servercmd>
 </reply>
 
index 4eb73e6cfde439a609a3288a7ead08070e21e483..873313848ef0acb0c9c0039e3e9a8c3da48e797b 100644 (file)
@@ -15,6 +15,7 @@ this is file contents
 </size>
 <servercmd>
 RETRNOSIZE
+REPLY SIZE 500 command not understood
 </servercmd>
 </reply>
 
diff --git a/tests/data/test1913 b/tests/data/test1913
new file mode 100644 (file)
index 0000000..daf7490
--- /dev/null
@@ -0,0 +1,41 @@
+<testcase>
+<info>
+<keywords>
+FTP
+CURLOPT_NOBODY
+</keywords>
+</info>
+
+# Server-side
+<reply>
+<servercmd>
+REPLY SIZE 550 no such file
+</servercmd>
+</reply>
+
+# Client-side
+<client>
+<server>
+ftp
+</server>
+
+# require debug so that alt-svc can work over plain old HTTP
+<name>
+FTP with NOBODY set, getting a missing file
+</name>
+<tool>
+lib1913
+</tool>
+
+<command>
+ftp://%HOSTIP:%FTPPORT/not-there/1913
+</command>
+</client>
+
+# Verify data after the test has been "shot"
+<verify>
+<errorcode>
+78
+</errorcode>
+</verify>
+</testcase>
diff --git a/tests/data/test1914 b/tests/data/test1914
new file mode 100644 (file)
index 0000000..1aa3e48
--- /dev/null
@@ -0,0 +1,42 @@
+<testcase>
+<info>
+<keywords>
+FTP
+CURLOPT_NOBODY
+CURLOPT_FILETIME
+</keywords>
+</info>
+
+# Server-side
+<reply>
+<servercmd>
+REPLY MDTM 550 no such file
+</servercmd>
+</reply>
+
+# Client-side
+<client>
+<server>
+ftp
+</server>
+
+# require debug so that alt-svc can work over plain old HTTP
+<name>
+FTP with NOBODY and FILETIME set, getting a missing file
+</name>
+<tool>
+lib1913
+</tool>
+
+<command>
+ftp://%HOSTIP:%FTPPORT/not-there/1913 1
+</command>
+</client>
+
+# Verify data after the test has been "shot"
+<verify>
+<errorcode>
+78
+</errorcode>
+</verify>
+</testcase>
index 625023221aa768f84063a5598a8c154c1a658696..94abb951ca9f20b64499ce0061a1bed9dff7cb50 100644 (file)
@@ -7,6 +7,9 @@ FTP
 
 # Server-side
 <reply>
+<servercmd>
+REPLY SIZE 500 command not understood
+</servercmd>
 </reply>
 
 # Client-side
index 9ba706f1dbf85275eb71a0b3324a2dccaca451b3..92e34bc3e096b283b10007425498fbe17eb6441e 100644 (file)
@@ -11,6 +11,7 @@ FTP
 REPLY SIZE 550 access to this file is very much denied
 REPLY APPE 550 I said: access to this file is very much denied
 REPLY STOR 550 I said: access to this file is very much denied
+REPLY SIZE 500 command not understood
 </servercmd>
 </reply>
 
index 72b79938cfdd098e25cc8f06690f943faa5efd01..1a251fd8925483d3f3b3cbd5f9a415f72298590e 100644 (file)
@@ -35,9 +35,9 @@ ftp://%HOSTIP:%FTPPORT/511
 #
 # Verify data after the test has been "shot"
 <verify>
-# CURLE_FTP_COULDNT_RETR_FILE
+# CURLE_REMOTE_FILE_NOT_FOUND
 <errorcode>
-19
+78
 </errorcode>
 <protocol>
 USER anonymous\r
index f4446cbe0058db0c0ec334279f8d7e1b72f602a9..a67c8c8245c7d92a41938814926c5952adb68829 100644 (file)
@@ -15,7 +15,7 @@ multi
 
 <servercmd>
 REPLY RETR 550 the file doesn't exist
-REPLY SIZE 550 Can't check for file existence
+REPLY SIZE 500 Can't check for file existence
 </servercmd>
 </reply>
 
index 6045dba61756423ee9478106bc06fff999c169c1..ba3f721e7f393ca53bb053edc99f1fd0de40753d 100644 (file)
@@ -16,7 +16,7 @@ non-existing host
 
 <servercmd>
 REPLY RETR 550 the file doesn't exist
-REPLY SIZE 550 Can't check for file existence
+REPLY SIZE 500 Can't check for file existence
 </servercmd>
 </reply>
 
index 12e604a0e8de04524a98fde37fa886db81bee9df..00dca99fa46ab4f8fff935aae28f99b2a9643853 100644 (file)
@@ -21,7 +21,7 @@ works
 <servercmd>
 REPLY RETR 550 the file doesn't exist
 COUNT RETR 1
-REPLY SIZE 550 Can't check for file existence
+REPLY SIZE 500 Can't check for file existence
 COUNT SIZE 1
 </servercmd>
 </reply>
index 4904515cd1afce046da496abb3bee6429125d84d..98fd2ee9f9bb89ba8955f433979472beb60860df 100644 (file)
@@ -58,7 +58,7 @@ noinst_PROGRAMS = chkhostname libauthretry libntlmconnect                \
  lib1550 lib1551 lib1552 lib1553 lib1554 lib1555 lib1556 lib1557 \
  lib1558 lib1559 lib1560 lib1564 lib1565 lib1567 \
  lib1591 lib1592 lib1593 lib1594 lib1596 \
-         lib1905 lib1906 lib1907 lib1908 lib1910 lib1911 lib1912 \
+         lib1905 lib1906 lib1907 lib1908 lib1910 lib1911 lib1912 lib1913 \
          lib3010
 
 chkdecimalpoint_SOURCES = chkdecimalpoint.c ../../lib/mprintf.c \
@@ -645,6 +645,10 @@ lib1912_SOURCES = lib1912.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
 lib1912_LDADD = $(TESTUTIL_LIBS)
 lib1912_CPPFLAGS = $(AM_CPPFLAGS)
 
+lib1913_SOURCES = lib1913.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
+lib1913_LDADD = $(TESTUTIL_LIBS)
+lib1913_CPPFLAGS = $(AM_CPPFLAGS)
+
 lib3010_SOURCES = lib3010.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
 lib3010_LDADD = $(TESTUTIL_LIBS)
 lib3010_CPPFLAGS = $(AM_CPPFLAGS)
diff --git a/tests/libtest/lib1913.c b/tests/libtest/lib1913.c
new file mode 100644 (file)
index 0000000..b8ef96e
--- /dev/null
@@ -0,0 +1,48 @@
+/***************************************************************************
+ *                                  _   _ ____  _
+ *  Project                     ___| | | |  _ \| |
+ *                             / __| | | | |_) | |
+ *                            | (__| |_| |  _ <| |___
+ *                             \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at https://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ***************************************************************************/
+#include "test.h"
+
+#include "testutil.h"
+#include "warnless.h"
+#include "memdebug.h"
+
+int test(char *URL)
+{
+  CURLcode ret = CURLE_OK;
+  CURL *hnd;
+  start_test_timing();
+
+  curl_global_init(CURL_GLOBAL_ALL);
+
+  hnd = curl_easy_init();
+  if(hnd) {
+    curl_easy_setopt(hnd, CURLOPT_URL, URL);
+    curl_easy_setopt(hnd, CURLOPT_NOBODY, 1L);
+    if(libtest_arg2)
+      /* test1914 sets this extra arg */
+      curl_easy_setopt(hnd, CURLOPT_FILETIME, 1L);
+    ret = curl_easy_perform(hnd);
+    curl_easy_cleanup(hnd);
+  }
+  curl_global_cleanup();
+  return (int)ret;
+}