]> granicus.if.org Git - curl/commitdiff
tftp tests: verify sent options too
authorDaniel Stenberg <daniel@haxx.se>
Fri, 6 Nov 2015 09:52:19 +0000 (10:52 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 6 Nov 2015 09:55:30 +0000 (10:55 +0100)
The tftpd test server now logs all received options and thus all TFTP
test cases need to match them exactly.

Extended test 283 to use and verify --tftp-blksize.

16 files changed:
tests/data/test1007
tests/data/test1009
tests/data/test1049
tests/data/test1093
tests/data/test1094
tests/data/test1099
tests/data/test1238
tests/data/test2002
tests/data/test2003
tests/data/test2004
tests/data/test271
tests/data/test283
tests/data/test284
tests/data/test285
tests/data/test286
tests/server/tftpd.c

index 5966ab366451813e52e45ffbb073b0fe8eb6c0c8..6baf221eb1fdc0508ce323b15f4caadbb4dede78 100644 (file)
@@ -32,8 +32,11 @@ This data will not be sent
 </errorcode>
 <protocol>
 opcode: 2
-filename: /invalid-file
 mode: octet
+tsize: 27
+blksize: 512
+timeout: 6
+filename: /invalid-file
 </protocol>
 </verify>
 </testcase>
index b0a93e5e08f3fbabb85ce186557276b233ad02f1..e1929beb27d501f10fc5be9f8cbc4056b5289ca1 100644 (file)
@@ -37,8 +37,11 @@ tftp://%HOSTIP:%TFTPPORT//1009 --local-port 44444-45444
 <verify>
 <protocol>
 opcode: 1
-filename: /1009
 mode: octet
+tsize: 0
+blksize: 512
+timeout: 6
+filename: /1009
 </protocol>
 </verify>
 </testcase>
index e6054a478c5c40a4e48e8927c11c0741db2dca81..60f41366d766b48b6410003af98c02938b6470ae 100644 (file)
@@ -37,8 +37,11 @@ tftp://%HOSTIP:%TFTPPORT//1049 --trace-ascii log/traceit --interface %CLIENTIP
 <verify>
 <protocol>
 opcode: 1
-filename: /1049
 mode: octet
+tsize: 0
+blksize: 512
+timeout: 6
+filename: /1049
 </protocol>
 </verify>
 </testcase>
index dbcfd9f7a86a35255dded6b544aad0ab50356fe9..2087c827811a664f95a31ef3e94afb4e2b64fa1d 100644 (file)
@@ -37,8 +37,11 @@ TFTP retrieve with mode=i
 <verify>
 <protocol>
 opcode: 1
-filename: /1093
 mode: octet
+tsize: 0
+blksize: 512
+timeout: 6
+filename: /1093
 </protocol>
 </verify>
 </testcase>
index 29965505f413508ea944180a854690e125f8575f..913172260490ab74bfbf0da7f96299c4a7d1511e 100644 (file)
@@ -43,8 +43,11 @@ TFTP retrieve with mode=netascii
 <verify>
 <protocol>
 opcode: 1
-filename: /1094
 mode: netascii
+tsize: 0
+blksize: 512
+timeout: 6
+filename: /1094
 </protocol>
 </verify>
 </testcase>
index cde4039746cc48cd7e71b32e1e92820551eccec4..7aacc11d06244831e2bd0d0242117467c08e9cec 100644 (file)
@@ -32,11 +32,17 @@ tftp://%HOSTIP:%TFTPPORT/an/invalid-file tftp://%HOSTIP:%TFTPPORT//1099 --trace-
 <verify>
 <protocol>
 opcode: 1
-filename: an/invalid-file
 mode: octet
+tsize: 0
+blksize: 512
+timeout: 6
+filename: an/invalid-file
 opcode: 1
-filename: /1099
 mode: octet
+tsize: 0
+blksize: 512
+timeout: 6
+filename: /1099
 </protocol>
 <stdout>
 data for 1099
index 18593398a0caae3aa27e1982ccea729c4c5750eb..4c976c776e34b22a1fa21cbc8e720c6a29c939be 100644 (file)
@@ -38,8 +38,11 @@ tftp://%HOSTIP:%TFTPPORT//1238 -Y1000 -y2
 <verify>
 <protocol>
 opcode: 1
-filename: /1238
 mode: octet
+tsize: 0
+blksize: 512
+timeout: 6
+filename: /1238
 </protocol>
 # 28 = CURLE_OPERATION_TIMEDOUT
 <errorcode>
index f39cd60f15ec607b620716cbc4dbe3e998c55e2b..db96bfea8035c0bce0045520404b6eb1ecd6e3aa 100644 (file)
@@ -88,8 +88,11 @@ TYPE I
 SIZE 20020002\r
 RETR 20020002\r
 opcode: 1
-filename: /20020003
 mode: octet
+tsize: 0
+blksize: 512
+timeout: 6
+filename: /20020003
 QUIT\r
 </protocol>
 <stdout>
index 57c0d24e6b37e63c27ae6ae50a09cc5cde830074..59a743f8577cccb7cec31fb5a7ceb39f95b87177 100644 (file)
@@ -88,11 +88,17 @@ TYPE I
 SIZE 20030002\r
 RETR 20030002\r
 opcode: 1
-filename: /20030003
 mode: octet
-opcode: 1
+tsize: 0
+blksize: 512
+timeout: 6
 filename: /20030003
+opcode: 1
 mode: octet
+tsize: 0
+blksize: 512
+timeout: 6
+filename: /20030003
 EPSV\r
 SIZE 20030002\r
 RETR 20030002\r
index bad6f7b900b7a19e3282f2617aa303005131b2e1..8035183bb167a918dea61cbc2b17314ea0b56c87 100644 (file)
@@ -43,11 +43,17 @@ for several protocols
 <verify>
 <protocol>
 opcode: 1
-filename: /2004
 mode: octet
-opcode: 1
+tsize: 0
+blksize: 512
+timeout: 6
 filename: /2004
+opcode: 1
 mode: octet
+tsize: 0
+blksize: 512
+timeout: 6
+filename: /2004
 </protocol>
 <stdout>
 Test data file
index af5a6c60318f5dd90ae6487d1a80c585d7a13ed6..06d5a8b43df72e2c19bbf9caf632083b3d3f6631 100644 (file)
@@ -36,8 +36,11 @@ tftp://%HOSTIP:%TFTPPORT//271 --trace-ascii log/traceit
 <verify>
 <protocol>
 opcode: 1
-filename: /271
 mode: octet
+tsize: 0
+blksize: 512
+timeout: 6
+filename: /271
 </protocol>
 </verify>
 </testcase>
index 922de51e0d5ecfc8e27c181060c8e9ccee98237e..0dc1270fdb2dacc813721853e2c9e02fe5d2986d 100644 (file)
@@ -17,7 +17,7 @@ tftp
 TFTP retrieve on invalid file
  </name>
  <command>
-tftp://%HOSTIP:%TFTPPORT//invalid-file --trace-ascii log/traceit
+tftp://%HOSTIP:%TFTPPORT//invalid-file --trace-ascii log/traceit --tftp-blksize 1024
 </command>
 </client>
 
@@ -29,8 +29,11 @@ tftp://%HOSTIP:%TFTPPORT//invalid-file --trace-ascii log/traceit
 </errorcode>
 <protocol>
 opcode: 1
-filename: /invalid-file
 mode: octet
+tsize: 0
+blksize: 1024
+timeout: 6
+filename: /invalid-file
 </protocol>
 </verify>
 </testcase>
index 0c2a665601c7300a831da9f3944898241e4e260b..954c902608310cb9e3adfaf6ff5a55a97df8a916 100644 (file)
@@ -60,8 +60,11 @@ tftp://%HOSTIP:%TFTPPORT//284 --trace-ascii log/traceit
 <verify>
 <protocol>
 opcode: 1
-filename: /284
 mode: octet
+tsize: 0
+blksize: 512
+timeout: 6
+filename: /284
 </protocol>
 </verify>
 </testcase>
index 75a19991d9bfc2d9fa9d4b1f079617bda44d2e15..d7a4a3900731e6f83ac31f1e576b4ceeac565ccd 100644 (file)
@@ -37,8 +37,11 @@ sent
 </upload>
 <protocol>
 opcode: 2
-filename: /test285.txt
 mode: octet
+tsize: 32
+blksize: 512
+timeout: 6
+filename: /test285.txt
 </protocol>
 </verify>
 </testcase>
index 841ee1e2a330a84c96124757f74024edf078f329..b909fd3d54ff6dafcc26c39a142027144e60cba0 100644 (file)
@@ -85,8 +85,11 @@ condition in the TFTP transmit code.
 </upload>
 <protocol>
 opcode: 2
-filename: /test286.txt
 mode: octet
+tsize: 512
+blksize: 512
+timeout: 6
+filename: /test286.txt
 </protocol>
 </verify>
 </testcase>
index cef129f2e3ca2b731bd866831d01f414082a560a..c2c512f11ed37f9cb51b9fea2c47d6e37e2450d4 100644 (file)
@@ -951,6 +951,8 @@ static int do_tftp(struct testcase *test, struct tftphdr *tp, ssize_t size)
 #ifdef USE_WINSOCK
   DWORD recvtimeout, recvtimeoutbak;
 #endif
+  char *option = (char *)"mode"; /* mode is implicit */
+  int toggle = 1;
 
   /* Open request dump file. */
   server = fopen(REQUEST_DUMP, "ab");
@@ -966,22 +968,48 @@ static int do_tftp(struct testcase *test, struct tftphdr *tp, ssize_t size)
 
   cp = (char *)&tp->th_stuff;
   filename = cp;
-again:
-  while (cp < &buf.storage[size]) {
-    if (*cp == '\0')
+  do {
+    bool endofit = true;
+    while (cp < &buf.storage[size]) {
+      if (*cp == '\0') {
+        endofit = false;
+        break;
+      }
+      cp++;
+    }
+    if(endofit)
+      /* no more options */
       break;
-    cp++;
-  }
+
+    /* before increasing pointer, make sure it is still within the legal
+       space */
+    if((cp+1) < &buf.storage[size]) {
+      ++cp;
+      if(first) {
+        /* store the mode since we need it later */
+        mode = cp;
+        first = 0;
+      }
+      if(toggle)
+        /* name/value pair: */
+        fprintf(server, "%s: %s\n", option, cp);
+      else {
+        /* store the name pointer */
+        option = cp;
+      }
+      toggle ^= 1;
+    }
+    else
+      /* No more options */
+      break;
+  } while(1);
+
   if (*cp) {
     nak(EBADOP);
     fclose(server);
     return 3;
   }
-  if (first) {
-    mode = ++cp;
-    first = 0;
-    goto again;
-  }
+
   /* store input protocol */
   fprintf(server, "filename: %s\n", filename);
 
@@ -990,7 +1018,6 @@ again:
       *cp = (char)tolower((int)*cp);
 
   /* store input protocol */
-  fprintf(server, "mode: %s\n", mode);
   fclose(server);
 
   for (pf = formata; pf->f_mode; pf++)