From 60c86297bf81235c18eec68f7ddf1a30f21aa1b7 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 6 Nov 2015 10:52:19 +0100 Subject: [PATCH] tftp tests: verify sent options too 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. --- tests/data/test1007 | 5 ++++- tests/data/test1009 | 5 ++++- tests/data/test1049 | 5 ++++- tests/data/test1093 | 5 ++++- tests/data/test1094 | 5 ++++- tests/data/test1099 | 10 +++++++-- tests/data/test1238 | 5 ++++- tests/data/test2002 | 5 ++++- tests/data/test2003 | 10 +++++++-- tests/data/test2004 | 10 +++++++-- tests/data/test271 | 5 ++++- tests/data/test283 | 7 +++++-- tests/data/test284 | 5 ++++- tests/data/test285 | 5 ++++- tests/data/test286 | 5 ++++- tests/server/tftpd.c | 49 ++++++++++++++++++++++++++++++++++---------- 16 files changed, 111 insertions(+), 30 deletions(-) diff --git a/tests/data/test1007 b/tests/data/test1007 index 5966ab366..6baf221eb 100644 --- a/tests/data/test1007 +++ b/tests/data/test1007 @@ -32,8 +32,11 @@ This data will not be sent opcode: 2 -filename: /invalid-file mode: octet +tsize: 27 +blksize: 512 +timeout: 6 +filename: /invalid-file diff --git a/tests/data/test1009 b/tests/data/test1009 index b0a93e5e0..e1929beb2 100644 --- a/tests/data/test1009 +++ b/tests/data/test1009 @@ -37,8 +37,11 @@ tftp://%HOSTIP:%TFTPPORT//1009 --local-port 44444-45444 opcode: 1 -filename: /1009 mode: octet +tsize: 0 +blksize: 512 +timeout: 6 +filename: /1009 diff --git a/tests/data/test1049 b/tests/data/test1049 index e6054a478..60f41366d 100644 --- a/tests/data/test1049 +++ b/tests/data/test1049 @@ -37,8 +37,11 @@ tftp://%HOSTIP:%TFTPPORT//1049 --trace-ascii log/traceit --interface %CLIENTIP opcode: 1 -filename: /1049 mode: octet +tsize: 0 +blksize: 512 +timeout: 6 +filename: /1049 diff --git a/tests/data/test1093 b/tests/data/test1093 index dbcfd9f7a..2087c8278 100644 --- a/tests/data/test1093 +++ b/tests/data/test1093 @@ -37,8 +37,11 @@ TFTP retrieve with mode=i opcode: 1 -filename: /1093 mode: octet +tsize: 0 +blksize: 512 +timeout: 6 +filename: /1093 diff --git a/tests/data/test1094 b/tests/data/test1094 index 29965505f..913172260 100644 --- a/tests/data/test1094 +++ b/tests/data/test1094 @@ -43,8 +43,11 @@ TFTP retrieve with mode=netascii opcode: 1 -filename: /1094 mode: netascii +tsize: 0 +blksize: 512 +timeout: 6 +filename: /1094 diff --git a/tests/data/test1099 b/tests/data/test1099 index cde403974..7aacc11d0 100644 --- a/tests/data/test1099 +++ b/tests/data/test1099 @@ -32,11 +32,17 @@ tftp://%HOSTIP:%TFTPPORT/an/invalid-file tftp://%HOSTIP:%TFTPPORT//1099 --trace- opcode: 1 +mode: octet +tsize: 0 +blksize: 512 +timeout: 6 filename: an/invalid-file -mode: octet opcode: 1 -filename: /1099 mode: octet +tsize: 0 +blksize: 512 +timeout: 6 +filename: /1099 data for 1099 diff --git a/tests/data/test1238 b/tests/data/test1238 index 18593398a..4c976c776 100644 --- a/tests/data/test1238 +++ b/tests/data/test1238 @@ -38,8 +38,11 @@ tftp://%HOSTIP:%TFTPPORT//1238 -Y1000 -y2 opcode: 1 -filename: /1238 mode: octet +tsize: 0 +blksize: 512 +timeout: 6 +filename: /1238 # 28 = CURLE_OPERATION_TIMEDOUT diff --git a/tests/data/test2002 b/tests/data/test2002 index f39cd60f1..db96bfea8 100644 --- a/tests/data/test2002 +++ b/tests/data/test2002 @@ -88,8 +88,11 @@ TYPE I SIZE 20020002 RETR 20020002 opcode: 1 -filename: /20020003 mode: octet +tsize: 0 +blksize: 512 +timeout: 6 +filename: /20020003 QUIT diff --git a/tests/data/test2003 b/tests/data/test2003 index 57c0d24e6..59a743f85 100644 --- a/tests/data/test2003 +++ b/tests/data/test2003 @@ -88,11 +88,17 @@ TYPE I SIZE 20030002 RETR 20030002 opcode: 1 -filename: /20030003 mode: octet +tsize: 0 +blksize: 512 +timeout: 6 +filename: /20030003 opcode: 1 -filename: /20030003 mode: octet +tsize: 0 +blksize: 512 +timeout: 6 +filename: /20030003 EPSV SIZE 20030002 RETR 20030002 diff --git a/tests/data/test2004 b/tests/data/test2004 index bad6f7b90..8035183bb 100644 --- a/tests/data/test2004 +++ b/tests/data/test2004 @@ -43,11 +43,17 @@ for several protocols opcode: 1 -filename: /2004 mode: octet +tsize: 0 +blksize: 512 +timeout: 6 +filename: /2004 opcode: 1 -filename: /2004 mode: octet +tsize: 0 +blksize: 512 +timeout: 6 +filename: /2004 Test data file diff --git a/tests/data/test271 b/tests/data/test271 index af5a6c603..06d5a8b43 100644 --- a/tests/data/test271 +++ b/tests/data/test271 @@ -36,8 +36,11 @@ tftp://%HOSTIP:%TFTPPORT//271 --trace-ascii log/traceit opcode: 1 -filename: /271 mode: octet +tsize: 0 +blksize: 512 +timeout: 6 +filename: /271 diff --git a/tests/data/test283 b/tests/data/test283 index 922de51e0..0dc1270fd 100644 --- a/tests/data/test283 +++ b/tests/data/test283 @@ -17,7 +17,7 @@ tftp TFTP retrieve on invalid file -tftp://%HOSTIP:%TFTPPORT//invalid-file --trace-ascii log/traceit +tftp://%HOSTIP:%TFTPPORT//invalid-file --trace-ascii log/traceit --tftp-blksize 1024 @@ -29,8 +29,11 @@ tftp://%HOSTIP:%TFTPPORT//invalid-file --trace-ascii log/traceit opcode: 1 -filename: /invalid-file mode: octet +tsize: 0 +blksize: 1024 +timeout: 6 +filename: /invalid-file diff --git a/tests/data/test284 b/tests/data/test284 index 0c2a66560..954c90260 100644 --- a/tests/data/test284 +++ b/tests/data/test284 @@ -60,8 +60,11 @@ tftp://%HOSTIP:%TFTPPORT//284 --trace-ascii log/traceit opcode: 1 -filename: /284 mode: octet +tsize: 0 +blksize: 512 +timeout: 6 +filename: /284 diff --git a/tests/data/test285 b/tests/data/test285 index 75a19991d..d7a4a3900 100644 --- a/tests/data/test285 +++ b/tests/data/test285 @@ -37,8 +37,11 @@ sent opcode: 2 -filename: /test285.txt mode: octet +tsize: 32 +blksize: 512 +timeout: 6 +filename: /test285.txt diff --git a/tests/data/test286 b/tests/data/test286 index 841ee1e2a..b909fd3d5 100644 --- a/tests/data/test286 +++ b/tests/data/test286 @@ -85,8 +85,11 @@ condition in the TFTP transmit code. opcode: 2 -filename: /test286.txt mode: octet +tsize: 512 +blksize: 512 +timeout: 6 +filename: /test286.txt diff --git a/tests/server/tftpd.c b/tests/server/tftpd.c index cef129f2e..c2c512f11 100644 --- a/tests/server/tftpd.c +++ b/tests/server/tftpd.c @@ -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++)