diff options
author | Haibo Huang <hhb@google.com> | 2019-01-08 14:27:10 -0800 |
---|---|---|
committer | Haibo Huang <hhb@google.com> | 2019-01-14 23:02:29 +0000 |
commit | 21926d584a5b118cbff81a9fb4329059011f87c6 (patch) | |
tree | 421b037a92a6d5209e8e4c30e8a830c262abe6d4 /tests | |
parent | 98caa6f514b401764e3ac76041ff7e006f109e8c (diff) | |
download | external_curl-21926d584a5b118cbff81a9fb4329059011f87c6.tar.gz external_curl-21926d584a5b118cbff81a9fb4329059011f87c6.tar.bz2 external_curl-21926d584a5b118cbff81a9fb4329059011f87c6.zip |
Upgrade curl from 7.62.0 to 7.63.0
Test: build, boots, `vendor/google/tools/fake-ota on streaming` works
Change-Id: Iecd6120501e7a6d2c8b83c2891de62163a30f08a
Diffstat (limited to 'tests')
63 files changed, 1356 insertions, 738 deletions
diff --git a/tests/FILEFORMAT b/tests/FILEFORMAT index 68a7854f..505c573c 100644 --- a/tests/FILEFORMAT +++ b/tests/FILEFORMAT @@ -220,7 +220,6 @@ SKIPPED. Features testable here are: -axTLS crypto debug getrlimit @@ -366,6 +365,8 @@ Available substitute variables include: %POP3PORT - Port number of the POP3 server %PROXYPORT - Port number of the HTTP proxy %PWD - Current directory +%POSIX_PWD - Current directory somewhat mingw friendly +%FILE_PWD - Current directory, on windows prefixed with a slash %RTSP6PORT - IPv6 port number of the RTSP server %RTSPPORT - Port number of the RTSP server %SMTP6PORT - IPv6 port number of the SMTP server diff --git a/tests/Makefile.am b/tests/Makefile.am index 77a9147e..64f5789d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -35,7 +35,7 @@ EXTRA_DIST = ftpserver.pl httpserver.pl secureserver.pl runtests.pl getpart.pm \ FILEFORMAT README stunnel.pem memanalyze.pl testcurl.pl valgrind.pm ftp.pm \ sshserver.pl sshhelp.pm pathhelp.pm testcurl.1 runtests.1 \ serverhelp.pm tftpserver.pl rtspserver.pl directories.pm symbol-scan.pl \ - CMakeLists.txt mem-include-scan.pl valgrind.supp http_pipe.py extern-scan.pl \ + CMakeLists.txt mem-include-scan.pl valgrind.supp extern-scan.pl \ manpage-scan.pl nroff-scan.pl http2-server.pl dictserver.py \ negtelnetserver.py $(SMBDEPS) diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc index 35c7aa4f..dd38f896 100644 --- a/tests/data/Makefile.inc +++ b/tests/data/Makefile.inc @@ -56,7 +56,7 @@ test289 test290 test291 test292 test293 test294 test295 test296 test297 \ test298 test299 test300 test301 test302 test303 test304 test305 test306 \ test307 test308 test309 test310 test311 test312 test313 test314 test315 \ test316 test317 test318 test319 test320 test321 test322 test323 test324 \ -test325 test326 \ +test325 test326 test327 test328 test329 \ \ test340 \ \ @@ -83,7 +83,7 @@ test617 test618 test619 test620 test621 test622 test623 test624 test625 \ test626 test627 test628 test629 test630 test631 test632 test633 test634 \ test635 test636 test637 test638 test639 test640 test641 test642 \ test643 test644 test645 test646 test647 test648 test649 test650 test651 \ -test652 test653 test654 test655 test656 \ +test652 test653 test654 test655 test656 test658 \ \ test700 test701 test702 test703 test704 test705 test706 test707 test708 \ test709 test710 test711 test712 test713 test714 test715 \ @@ -127,7 +127,7 @@ test1120 test1121 test1122 test1123 test1124 test1125 test1126 test1127 \ test1128 test1129 test1130 test1131 test1132 test1133 test1134 test1135 \ test1136 test1137 test1138 test1139 test1140 test1141 test1142 test1143 \ test1144 test1145 test1146 test1147 test1148 test1149 test1150 test1151 \ -test1152 test1153 test1154 test1155 test1156 test1157 test1158 \ +test1152 test1153 test1154 test1155 test1156 test1157 test1158 test1159 \ \ test1160 test1161 test1162 test1163 test1164 \ test1170 test1171 \ @@ -166,12 +166,10 @@ test1424 test1425 test1426 test1427 \ test1428 test1429 test1430 test1431 test1432 test1433 test1434 test1435 \ test1436 test1437 test1438 test1439 test1440 test1441 test1442 test1443 \ test1444 test1445 test1446 test1447 test1448 test1449 test1450 test1451 \ -test1452 test1453 test1454 test1455 test1456 \ +test1452 test1453 test1454 test1455 test1456 test1457 \ test1500 test1501 test1502 test1503 test1504 test1505 test1506 test1507 \ test1508 test1509 test1510 test1511 test1512 test1513 test1514 test1515 \ -test1516 test1517 \ -\ -test1520 test1521 test1522 \ +test1516 test1517 test1518 test1519 test1520 test1521 test1522 \ \ test1525 test1526 test1527 test1528 test1529 test1530 test1531 test1532 \ test1533 test1534 test1535 test1536 test1537 test1538 \ @@ -184,7 +182,7 @@ test1590 \ test1600 test1601 test1602 test1603 test1604 test1605 test1606 test1607 \ test1608 test1609 test1620 \ \ -test1650 test1651 \ +test1650 test1651 test1652 test1653 \ \ test1700 test1701 test1702 \ \ @@ -201,7 +199,7 @@ test2040 test2041 test2042 test2043 test2044 test2045 test2046 test2047 \ test2048 test2049 test2050 test2051 test2052 test2053 test2054 test2055 \ test2056 test2057 test2058 test2059 test2060 test2061 test2062 test2063 \ test2064 test2065 test2066 test2067 test2068 test2069 \ -test2070 test2071 test2072 test2073 test2074 test2075 \ + test2071 test2072 test2073 test2074 test2075 test2076 \ test2080 \ test2100 \ \ diff --git a/tests/data/test1159 b/tests/data/test1159 new file mode 100644 index 00000000..a5160165 --- /dev/null +++ b/tests/data/test1159 @@ -0,0 +1,58 @@ +<testcase> +<info> +<keywords> +HTTP +HTTP GET +redirect_url +followlocation +--write-out +</keywords> +</info> + +# Server-side +<reply> +<data nocheck="yes"> +HTTP/1.1 301 This is a weirdo text message swsclose
+Location: ht3p://localhost/
+Content-Length: 62
+Connection: close
+
+This server reply is for testing a simple Location: following +</data> +</reply> + +# Client-side +<client> +<server> +http +</server> + <name> +HTTP Location: and 'redirect_url' with non-supported scheme + </name> +<command> +http://%HOSTIP:%HTTPPORT/we/want/our/1159 -w '%{redirect_url}\n' +</command> +</client> + +# Verify data after the test has been "shot" +<verify> +<strip> +^User-Agent:.* +</strip> +<protocol> +GET /we/want/our/1159 HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+Accept: */*
+
+</protocol> +<stdout> +HTTP/1.1 301 This is a weirdo text message swsclose
+Location: ht3p://localhost/
+Content-Length: 62
+Connection: close
+
+This server reply is for testing a simple Location: following +ht3p://localhost/ +</stdout> +</verify> +</testcase> diff --git a/tests/data/test1160 b/tests/data/test1160 index 26a758c4..3fe689e9 100644 --- a/tests/data/test1160 +++ b/tests/data/test1160 @@ -43,7 +43,11 @@ Host: %HOSTIP:%HTTPPORT Accept: */*
</protocol> -<file name="log/cookies1160.txt"> +<file name="log/cookies1160.txt" mode="text"> +# Netscape HTTP Cookie File +# https://curl.haxx.se/docs/http-cookies.html +# This file was generated by libcurl! Edit at your own risk. + </file> </verify> </testcase> diff --git a/tests/data/test1322 b/tests/data/test1322 index bf10a8d0..97498951 100644 --- a/tests/data/test1322 +++ b/tests/data/test1322 @@ -37,7 +37,7 @@ http HTTP with --resolve and hostname with trailing dot </name> <command> ---resolve example.com:%HTTPPORT:%HOSTIP http://example.com.:%HTTPPORT/1322 +--ipv4 --resolve example.com.:%HTTPPORT:%HOSTIP http://example.com.:%HTTPPORT/1322 </command> </client> diff --git a/tests/data/test1457 b/tests/data/test1457 new file mode 100644 index 00000000..aad6d43d --- /dev/null +++ b/tests/data/test1457 @@ -0,0 +1,62 @@ +<testcase> +<info> +<keywords> +protocol +--write-out +</keywords> +</info> +# Server-side +<reply> +<data nocheck="yes"> +HTTP/1.1 200 OK +Date: Thu, 09 Nov 2010 14:49:00 GMT +Content-Length: 9 +Connection: close +Content-Type: text/plain + +testdata +</data> + +</reply> + +# Client-side +<client> +<server> +http +</server> + +<name> +Check if %{stderr} and %{stdout} switch between stdout and stderr. +</name> +<command> +http://%HOSTIP:%HTTPPORT/1457 --write-out 'line1%{stderr}line2%{stdout}line3' +</command> +</client> + +# Verify data +<verify> +<stdout nonewline="yes"> +HTTP/1.1 200 OK +Date: Thu, 09 Nov 2010 14:49:00 GMT +Content-Length: 9 +Connection: close +Content-Type: text/plain + +testdata +line1line3 +</stdout> +#note: as of now <stderr> doesn't actually exist in runtests.pl +<stderr nonewline="yes"> +line2 +</stderr> +<protocol> +GET /1457 HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+Accept: */*
+
+</protocol> +<strip> +^User-Agent:.* +</strip> +</verify> +</testcase> diff --git a/tests/data/test1518 b/tests/data/test1518 new file mode 100644 index 00000000..134ea4af --- /dev/null +++ b/tests/data/test1518 @@ -0,0 +1,62 @@ +<testcase> +<info> +<keywords> +HTTP +</keywords> +</info> +# +# This reproduces issue #3340 +# +# Server-side +<reply> +<data nocheck="yes"> +HTTP/1.1 302 redirect to broken URL +Date: Thu, 17 Mar 2016 14:41:00 GMT +Server: test-server/fake +Content-Type: text/plain; charset=US-ASCII +X-Special: swsclose +Location: http://1.2 .4.5/test +Content-Length: 0 +Connection: close + +</data> +</reply> + +# Client-side +<client> +<server> +http +</server> +# tool is what to use instead of 'curl' +<tool> +lib1518 +</tool> + + <name> +Extract Location: with broken URL + </name> + <command> +http://%HOSTIP:%HTTPPORT/1518 +</command> +</client> + +# +# Verify data after the test has been "shot" +<verify> +<strippart> + +</strippart> +<protocol> +</protocol> +<stdout> +res: 0 +status: 302 +redirects: 0 +effectiveurl: http://%HOSTIP:%HTTPPORT/1518 +redirecturl: http://1.2 .4.5/test +</stdout> +<errorcode> +0 +</errorcode> +</verify> +</testcase> diff --git a/tests/data/test1519 b/tests/data/test1519 new file mode 100644 index 00000000..ab23dadc --- /dev/null +++ b/tests/data/test1519 @@ -0,0 +1,62 @@ +<testcase> +<info> +<keywords> +HTTP +</keywords> +</info> +# +# This reproduces issue #3340 +# +# Server-side +<reply> +<data nocheck="yes"> +HTTP/1.1 302 redirect to broken URL +Date: Thu, 17 Mar 2016 14:41:00 GMT +Server: test-server/fake +Content-Type: text/plain; charset=US-ASCII +X-Special: swsclose +Location: h ttp://1.2.4.5/test +Content-Length: 0 +Connection: close + +</data> +</reply> + +# Client-side +<client> +<server> +http +</server> +# tool is what to use instead of 'curl' +<tool> +lib1518 +</tool> + + <name> +Extract Location: with broken absolute URL + </name> + <command> +http://%HOSTIP:%HTTPPORT/1519 +</command> +</client> + +# +# Verify data after the test has been "shot" +<verify> +<strippart> + +</strippart> +<protocol> +</protocol> +<stdout> +res: 0 +status: 302 +redirects: 0 +effectiveurl: http://%HOSTIP:%HTTPPORT/1519 +redirecturl: http://127.0.0.1:8990/h%20ttp://1.2.4.5/test +</stdout> +<errorcode> +0 +</errorcode> +</verify> +</testcase> diff --git a/tests/data/test1652 b/tests/data/test1652 new file mode 100644 index 00000000..c4116901 --- /dev/null +++ b/tests/data/test1652 @@ -0,0 +1,23 @@ +<testcase> +<info> +<keywords> +unittest +infof +</keywords> +</info> + +<client> +<server> +none +</server> +<features> +unittest +</features> +<name> +infof +</name> +<tool> +unit1652 +</tool> +</client> +</testcase> diff --git a/tests/data/test1653 b/tests/data/test1653 new file mode 100644 index 00000000..0de2c14b --- /dev/null +++ b/tests/data/test1653 @@ -0,0 +1,23 @@ +<testcase> +<info> +<keywords> +unittest +urlapi +</keywords> +</info> + +<client> +<server> +none +</server> +<features> +unittest +</features> +<name> +urlapi +</name> +<tool> +unit1653 +</tool> +</client> +</testcase> diff --git a/tests/data/test20 b/tests/data/test20 index 57fa48de..910cb54c 100644 --- a/tests/data/test20 +++ b/tests/data/test20 @@ -25,7 +25,7 @@ http attempt connect to non-existing host name </name> <command> -non-existing-host.haxx.se. +--ipv4 non-existing-host.haxx.se. </command> </client> diff --git a/tests/data/test203 b/tests/data/test203 index 39384265..ee850cb1 100644 --- a/tests/data/test203 +++ b/tests/data/test203 @@ -24,8 +24,12 @@ file <name> file:/path URL with a single slash </name> +<setenv> +# Needed for MSYS2 to not convert +MSYS2_ARG_CONV_EXCL=file: +</setenv> <command option="no-include"> -file:%PWD/log/test203.txt +file:%FILE_PWD/log/test203.txt </command> <file name="log/test203.txt"> foo diff --git a/tests/data/test2070 b/tests/data/test2070 deleted file mode 100644 index 655cd8a3..00000000 --- a/tests/data/test2070 +++ /dev/null @@ -1,41 +0,0 @@ -<testcase> -<info> -<keywords> -FILE -</keywords> -</info> - -<reply> -<data> -foo - bar -bar - foo -moo -</data> -</reply> - -# Client-side -<client> -<server> -file -</server> - <name> -basic file:// file with no authority - </name> -<command option="no-include"> -file:%PWD/log/test2070.txt -</command> -<file name="log/test2070.txt"> -foo - bar -bar - foo -moo -</file> -</client> - -# Verify data after the test has been "shot" -<verify> -</verify> -</testcase> diff --git a/tests/data/test2076 b/tests/data/test2076 new file mode 100644 index 00000000..2c477b1a --- /dev/null +++ b/tests/data/test2076 @@ -0,0 +1,75 @@ +<testcase> +<info> +<keywords> +HTTP +HTTP GET +HTTP Digest auth +</keywords> +</info> +# Server-side +<reply> +<data> +HTTP/1.1 401 Authorization Required swsclose
+WWW-Authenticate: Digest realm="testrealm", nonce="1"
+Content-Length: 26
+
+This is not the real page +</data> + +# This is supposed to be returned when the server gets a +# Authorization: Digest line passed-in from the client +<data1000> +HTTP/1.1 200 OK swsclose
+Content-Length: 23
+
+This IS the real page! +</data1000> + +<datacheck> +HTTP/1.1 401 Authorization Required swsclose
+WWW-Authenticate: Digest realm="testrealm", nonce="1"
+Content-Length: 26
+
+HTTP/1.1 200 OK swsclose
+Content-Length: 23
+
+This IS the real page! +</datacheck> + +</reply> + +# Client-side +<client> +<server> +http +</server> +<features> +!SSPI +crypto +</features> +<name> +HTTP with digest auth and URI contains query +</name> +<command> +"http://%HOSTIP:%HTTPPORT/2076?query" -u testuser:testpass --digest +</command> +</client> + +# Verify data after the test has been "shot" +<verify> +<strip> +^User-Agent:.* +</strip> +<protocol> +GET /2076?query HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+Accept: */*
+
+GET /2076?query HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+Authorization: Digest username="testuser", realm="testrealm", nonce="1", uri="/2076?query", response="5758bd3bbde7f33236e6ccd278eb59af"
+Accept: */*
+
+</protocol> +</verify> +</testcase> diff --git a/tests/data/test327 b/tests/data/test327 new file mode 100644 index 00000000..fcb98990 --- /dev/null +++ b/tests/data/test327 @@ -0,0 +1,73 @@ +<testcase> +<info> +<keywords> +HTTP +HTTP GET +cookies +header dump +</keywords> +</info> + +# This test verifies that the cookie file gets created even if the last cookie +# has been removed - particularly important when the file is going to be read +# again and thus must not contain old contents. + +# Server-side +<reply> +<data> +HTTP/1.1 200 OK +Date: Thu, 09 Nov 2010 14:49:00 GMT +Server: test-server/fake +Content-Type: text/html +Funny-head: yesyes swsclose +Set-Cookie: foobar=name; expires=Thu, 22 Nov 2028 10:54:11 GMT; + +</data> +<data2> +HTTP/1.1 200 OK +Date: Thu, 09 Nov 2010 14:49:00 GMT +Server: test-server/fake +Content-Type: text/html +Funny-head: yesyes swsclose +Set-Cookie: foobar=name; expires=Thu, 01 Jan 1970 00:00:00 GMT; + +</data> +</reply> + +# Client-side +<client> +<server> +http +</server> + <name> +HTTP with cookiejar without cookies left + </name> + <command> +http://%HOSTIP:%HTTPPORT/we/want/327 -b none -c log/cookies327 http://%HOSTIP:%HTTPPORT/we/want/3270002 +</command> +</client> + +# Verify data after the test has been "shot" +<verify> +<strip> +^User-Agent:.* +</strip> +<protocol> +GET /we/want/327 HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+Accept: */*
+
+GET /we/want/3270002 HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+Accept: */*
+Cookie: foobar=name
+
+</protocol> +<file name="log/cookies327" mode="text"> +# Netscape HTTP Cookie File +# https://curl.haxx.se/docs/http-cookies.html +# This file was generated by libcurl! Edit at your own risk. + +</file> +</verify> +</testcase> diff --git a/tests/data/test328 b/tests/data/test328 new file mode 100644 index 00000000..93c00e18 --- /dev/null +++ b/tests/data/test328 @@ -0,0 +1,55 @@ +<testcase> +<info> +<keywords> +HTTP +HTTP GET +Content-Encoding +</keywords> +</info> + +# Server-side +<reply> +<data> +HTTP/1.1 200 OK +Date: Thu, 09 Nov 2010 14:49:00 GMT +Content-Type: text/html +Content-Encoding: none +Content-Length: 38 + +Q: What did 0 say to 8? A: Nice Belt! +</data> +</reply> + +# Client-side +<client> +<server> +http +</server> + +# we're actually more interested in any compression support but this is the +# best we can do right now +<features> +libz +</features> + <name> +HTTP with "Content-Encoding: none + </name> + <command> +http://%HOSTIP:%HTTPPORT/hello/328 --compressed +</command> +</client> + +# Verify data after the test has been "shot" +<verify> +<strip> +^User-Agent:.* +^Accept-Encoding:.* +</strip> +<protocol> +GET /hello/328 HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+Accept: */*
+
+</protocol> +</verify> +</testcase> diff --git a/tests/data/test329 b/tests/data/test329 new file mode 100644 index 00000000..c9e3d9d4 --- /dev/null +++ b/tests/data/test329 @@ -0,0 +1,70 @@ +<testcase> +<info> +<keywords> +HTTP +HTTP GET +cookies +</keywords> +</info> +# Server-side +<reply> +<data> +HTTP/1.1 200 OK
+Date: Thu, 09 Nov 2010 14:49:00 GMT
+Server: test-server/fake
+Content-Type: text/html
+Funny-head: yesyes
+Set-Cookie: test=yes; path=/we/want/; domain=.host.foo.com; Max-Age=0;
+Content-Length: 4
+
+boo +</data> +<data2> +HTTP/1.1 200 OK
+Funny-head: yesyes
+Content-Length: 4
+
+moo +</data2> +</reply> + +# Client-side +<client> +<file name="log/jar329.txt" mode="text"> +.host.foo.com TRUE /we/want/ FALSE 2054030187 test no +</file> +<server> +http +</server> + <name> +HTTP cookie with Max-Age=0 + </name> +# Explicitly set the time zone to a known good one, in case the user is +# using one of the 'right' zones that take into account leap seconds +# which causes the cookie expiry times to be different. +<setenv> +TZ=GMT +</setenv> + <command> +http://%HOSTIP:%HTTPPORT/we/want/329 -b log/jar329.txt -H "Host: host.foo.com" http://%HOSTIP:%HTTPPORT/we/want/3290002 +</command> +</client> + +# Verify data after the test has been "shot" +<verify> +<strip> +^User-Agent:.* +</strip> +<protocol> +GET /we/want/329 HTTP/1.1
+Host: host.foo.com
+Accept: */*
+Cookie: test=no
+
+GET /we/want/3290002 HTTP/1.1
+Host: host.foo.com
+Accept: */*
+
+</protocol> +</verify> +</testcase> diff --git a/tests/data/test658 b/tests/data/test658 new file mode 100644 index 00000000..c75293c6 --- /dev/null +++ b/tests/data/test658 @@ -0,0 +1,50 @@ +<testcase> +<info> +<keywords> +HTTP +HTTP GET +</keywords> +</info> +<reply> +<data nocheck="yes"> +HTTP/1.1 200 OK +Date: Thu, 09 Nov 2010 14:49:00 GMT +Server: test-server/fake +Last-Modified: Tue, 13 Jun 2000 12:10:00 GMT +ETag: "21025-dc7-39462498" +Accept-Ranges: bytes +Content-Length: 6 +Connection: close +Content-Type: text/html +Funny-head: yesyes + +-foo- +</data> +</reply> +<client> +<server> +http +</server> +<tool> +lib658 +</tool> +<name> +HTTP GET + </name> + <command> +http://%HOSTIP:%HTTPPORT/658 +</command> +</client> + +<verify> +<strip> +^User-Agent:.* +</strip> +<protocol> +GET /658 HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+Accept: */*
+
+</verify> + +</testcase> diff --git a/tests/http_pipe.py b/tests/http_pipe.py deleted file mode 100755 index 95389f49..00000000 --- a/tests/http_pipe.py +++ /dev/null @@ -1,441 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2012 Google Inc. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Modified by Linus Nielsen Feltzing for inclusion in the libcurl test -# framework -# -try: - import socketserver -except: - import SocketServer as socketserver -import argparse -import re -import select -import socket -import time -import pprint -import os - -INFO_MESSAGE = ''' -This is a test server to test the libcurl pipelining functionality. -It is a modified version if Google's HTTP pipelining test server. More -information can be found here: - -https://dev.chromium.org/developers/design-documents/network-stack/http-pipelining - -Source code can be found here: - -https://code.google.com/archive/p/http-pipelining-test/ -''' -MAX_REQUEST_SIZE = 1024 # bytes -MIN_POLL_TIME = 0.01 # seconds. Minimum time to poll, in order to prevent - # excessive looping because Python refuses to poll for - # small timeouts. -SEND_BUFFER_TIME = 0.5 # seconds -TIMEOUT = 30 # seconds - - -class Error(Exception): - pass - - -class RequestTooLargeError(Error): - pass - - -class ServeIndexError(Error): - pass - - -class UnexpectedMethodError(Error): - pass - - -class RequestParser(object): - """Parses an input buffer looking for HTTP GET requests.""" - - global logfile - - LOOKING_FOR_GET = 1 - READING_HEADERS = 2 - - HEADER_RE = re.compile('([^:]+):(.*)\n') - REQUEST_RE = re.compile('([^ ]+) ([^ ]+) HTTP/(\d+)\.(\d+)\n') - - def __init__(self): - """Initializer.""" - self._buffer = "" - self._pending_headers = {} - self._pending_request = "" - self._state = self.LOOKING_FOR_GET - self._were_all_requests_http_1_1 = True - self._valid_requests = [] - - def ParseAdditionalData(self, data): - """Finds HTTP requests in |data|. - - Args: - data: (String) Newly received input data from the socket. - - Returns: - (List of Tuples) - (String) The request path. - (Map of String to String) The header name and value. - - Raises: - RequestTooLargeError: If the request exceeds MAX_REQUEST_SIZE. - UnexpectedMethodError: On a non-GET method. - Error: On a programming error. - """ - logfile = open('log/server.input', 'a') - logfile.write(data) - logfile.close() - self._buffer += data.replace('\r', '') - should_continue_parsing = True - while should_continue_parsing: - if self._state == self.LOOKING_FOR_GET: - should_continue_parsing = self._DoLookForGet() - elif self._state == self.READING_HEADERS: - should_continue_parsing = self._DoReadHeader() - else: - raise Error('Unexpected state: ' + self._state) - if len(self._buffer) > MAX_REQUEST_SIZE: - raise RequestTooLargeError( - 'Request is at least %d bytes' % len(self._buffer)) - valid_requests = self._valid_requests - self._valid_requests = [] - return valid_requests - - @property - def were_all_requests_http_1_1(self): - return self._were_all_requests_http_1_1 - - def _DoLookForGet(self): - """Tries to parse an HTTTP request line. - - Returns: - (Boolean) True if a request was found. - - Raises: - UnexpectedMethodError: On a non-GET method. - """ - m = self.REQUEST_RE.match(self._buffer) - if not m: - return False - method, path, http_major, http_minor = m.groups() - - if method != 'GET': - raise UnexpectedMethodError('Unexpected method: ' + method) - if path in ['/', '/index.htm', '/index.html']: - raise ServeIndexError() - - if http_major != '1' or http_minor != '1': - self._were_all_requests_http_1_1 = False - -# print method, path - - self._pending_request = path - self._buffer = self._buffer[m.end():] - self._state = self.READING_HEADERS - return True - - def _DoReadHeader(self): - """Tries to parse a HTTP header. - - Returns: - (Boolean) True if it found the end of the request or a HTTP header. - """ - if self._buffer.startswith('\n'): - self._buffer = self._buffer[1:] - self._state = self.LOOKING_FOR_GET - self._valid_requests.append((self._pending_request, - self._pending_headers)) - self._pending_headers = {} - self._pending_request = "" - return True - - m = self.HEADER_RE.match(self._buffer) - if not m: - return False - - header = m.group(1).lower() - value = m.group(2).strip().lower() - if header not in self._pending_headers: - self._pending_headers[header] = value - self._buffer = self._buffer[m.end():] - return True - - -class ResponseBuilder(object): - """Builds HTTP responses for a list of accumulated requests.""" - - def __init__(self): - """Initializer.""" - self._max_pipeline_depth = 0 - self._requested_paths = [] - self._processed_end = False - self._were_all_requests_http_1_1 = True - - def QueueRequests(self, requested_paths, were_all_requests_http_1_1): - """Adds requests to the queue of requests. - - Args: - requested_paths: (List of Strings) Requested paths. - """ - self._requested_paths.extend(requested_paths) - self._were_all_requests_http_1_1 = were_all_requests_http_1_1 - - def Chunkify(self, data, chunksize): - """ Divides a string into chunks - """ - return [hex(chunksize)[2:] + "\r\n" + data[i:i+chunksize] + "\r\n" for i in range(0, len(data), chunksize)] - - def BuildResponses(self): - """Converts the queue of requests into responses. - - Returns: - (String) Buffer containing all of the responses. - """ - result = "" - self._max_pipeline_depth = max(self._max_pipeline_depth, - len(self._requested_paths)) - for path, headers in self._requested_paths: - if path == '/verifiedserver': - body = "WE ROOLZ: {}\r\n".format(os.getpid()); - result += self._BuildResponse( - '200 OK', ['Server: Apache', - 'Content-Length: {}'.format(len(body)), - 'Cache-Control: no-store'], body) - - elif path == '/alphabet.txt': - body = 'abcdefghijklmnopqrstuvwxyz' - result += self._BuildResponse( - '200 OK', ['Server: Apache', - 'Content-Length: 26', - 'Cache-Control: no-store'], body) - - elif path == '/reverse.txt': - body = 'zyxwvutsrqponmlkjihgfedcba' - result += self._BuildResponse( - '200 OK', ['Content-Length: 26', 'Cache-Control: no-store'], body) - - elif path == '/chunked.txt': - body = ('7\r\nchunked\r\n' - '8\r\nencoding\r\n' - '2\r\nis\r\n' - '3\r\nfun\r\n' - '0\r\n\r\n') - result += self._BuildResponse( - '200 OK', ['Transfer-Encoding: chunked', 'Cache-Control: no-store'], - body) - - elif path == '/cached.txt': - body = 'azbycxdwevfugthsirjqkplomn' - result += self._BuildResponse( - '200 OK', ['Content-Length: 26', 'Cache-Control: max-age=60'], body) - - elif path == '/connection_close.txt': - body = 'azbycxdwevfugthsirjqkplomn' - result += self._BuildResponse( - '200 OK', ['Content-Length: 26', 'Cache-Control: max-age=60', 'Connection: close'], body) - self._processed_end = True - - elif path == '/1k.txt': - body = '0123456789abcdef' * 64 - result += self._BuildResponse( - '200 OK', ['Server: Apache', - 'Content-Length: 1024', - 'Cache-Control: max-age=60'], body) - - elif path == '/10k.txt': - body = '0123456789abcdef' * 640 - result += self._BuildResponse( - '200 OK', ['Server: Apache', - 'Content-Length: 10240', - 'Cache-Control: max-age=60'], body) - - elif path == '/100k.txt': - body = '0123456789abcdef' * 6400 - result += self._BuildResponse( - '200 OK', - ['Server: Apache', - 'Content-Length: 102400', - 'Cache-Control: max-age=60'], - body) - - elif path == '/100k_chunked.txt': - body = self.Chunkify('0123456789abcdef' * 6400, 20480) - body.append('0\r\n\r\n') - body = ''.join(body) - - result += self._BuildResponse( - '200 OK', ['Transfer-Encoding: chunked', 'Cache-Control: no-store'], body) - - elif path == '/stats.txt': - results = { - 'max_pipeline_depth': self._max_pipeline_depth, - 'were_all_requests_http_1_1': int(self._were_all_requests_http_1_1), - } - body = ','.join(['%s:%s' % (k, v) for k, v in results.items()]) - result += self._BuildResponse( - '200 OK', - ['Content-Length: %s' % len(body), 'Cache-Control: no-store'], body) - self._processed_end = True - - else: - result += self._BuildResponse('404 Not Found', ['Content-Length: 7'], 'Go away') - if self._processed_end: - break - self._requested_paths = [] - return result - - def WriteError(self, status, error): - """Returns an HTTP response for the specified error. - - Args: - status: (String) Response code and descrtion (e.g. "404 Not Found") - - Returns: - (String) Text of HTTP response. - """ - return self._BuildResponse( - status, ['Connection: close', 'Content-Type: text/plain'], error) - - @property - def processed_end(self): - return self._processed_end - - def _BuildResponse(self, status, headers, body): - """Builds an HTTP response. - - Args: - status: (String) Response code and descrtion (e.g. "200 OK") - headers: (List of Strings) Headers (e.g. "Connection: close") - body: (String) Response body. - - Returns: - (String) Text of HTTP response. - """ - return ('HTTP/1.1 %s\r\n' - '%s\r\n' - '\r\n' - '%s' % (status, '\r\n'.join(headers), body)) - - -class PipelineRequestHandler(socketserver.BaseRequestHandler): - """Called on an incoming TCP connection.""" - - def _GetTimeUntilTimeout(self): - return self._start_time + TIMEOUT - time.time() - - def _GetTimeUntilNextSend(self): - if not self._last_queued_time: - return TIMEOUT - return self._last_queued_time + SEND_BUFFER_TIME - time.time() - - def handle(self): - self._request_parser = RequestParser() - self._response_builder = ResponseBuilder() - self._last_queued_time = 0 - self._num_queued = 0 - self._num_written = 0 - self._send_buffer = "" - self._start_time = time.time() - try: - while not self._response_builder.processed_end or self._send_buffer: - - time_left = self._GetTimeUntilTimeout() - time_until_next_send = self._GetTimeUntilNextSend() - max_poll_time = min(time_left, time_until_next_send) + MIN_POLL_TIME - - rlist, wlist, xlist = [], [], [] - fileno = self.request.fileno() - if max_poll_time > 0: - rlist.append(fileno) - if self._send_buffer: - wlist.append(fileno) - rlist, wlist, xlist = select.select(rlist, wlist, xlist, max_poll_time) - - if self._GetTimeUntilTimeout() <= 0: - return - - if self._GetTimeUntilNextSend() <= 0: - self._send_buffer += self._response_builder.BuildResponses() - self._num_written = self._num_queued - self._last_queued_time = 0 - - if fileno in rlist: - self.request.setblocking(False) - new_data = self.request.recv(MAX_REQUEST_SIZE) - self.request.setblocking(True) - if not new_data: - return - new_requests = self._request_parser.ParseAdditionalData(new_data) - self._response_builder.QueueRequests( - new_requests, self._request_parser.were_all_requests_http_1_1) - self._num_queued += len(new_requests) - self._last_queued_time = time.time() - elif fileno in wlist: - num_bytes_sent = self.request.send(self._send_buffer[0:4096]) - self._send_buffer = self._send_buffer[num_bytes_sent:] - time.sleep(0.05) - - except RequestTooLargeError as e: - self.request.send(self._response_builder.WriteError( - '413 Request Entity Too Large', e)) - raise - except UnexpectedMethodError as e: - self.request.send(self._response_builder.WriteError( - '405 Method Not Allowed', e)) - raise - except ServeIndexError: - self.request.send(self._response_builder.WriteError( - '200 OK', INFO_MESSAGE)) - except Exception as e: - print(e) - self.request.close() - - -class PipelineServer(socketserver.ThreadingMixIn, socketserver.TCPServer): - pass - - -parser = argparse.ArgumentParser() -parser.add_argument("--port", action="store", default=0, - type=int, help="port to listen on") -parser.add_argument("--verbose", action="store", default=0, - type=int, help="verbose output") -parser.add_argument("--pidfile", action="store", default=0, - help="file name for the PID") -parser.add_argument("--logfile", action="store", default=0, - help="file name for the log") -parser.add_argument("--srcdir", action="store", default=0, - help="test directory") -parser.add_argument("--id", action="store", default=0, - help="server ID") -parser.add_argument("--ipv4", action="store_true", default=0, - help="IPv4 flag") -args = parser.parse_args() - -if args.pidfile: - pid = os.getpid() - f = open(args.pidfile, 'w') - f.write('{}'.format(pid)) - f.close() - -server = PipelineServer(('0.0.0.0', args.port), PipelineRequestHandler) -server.allow_reuse_address = True -server.serve_forever() diff --git a/tests/libtest/Makefile.inc b/tests/libtest/Makefile.inc index 7a3cd166..080421b2 100644 --- a/tests/libtest/Makefile.inc +++ b/tests/libtest/Makefile.inc @@ -21,11 +21,11 @@ noinst_PROGRAMS = chkhostname libauthretry libntlmconnect \ lib559 lib560 lib562 lib564 lib565 lib566 lib567 lib568 lib569 lib570 \ lib571 lib572 lib573 lib574 lib575 lib576 lib578 lib579 lib582 \ lib583 lib585 lib586 lib587 lib589 lib590 lib591 lib597 lib598 lib599 \ - lib643 lib644 lib645 lib650 lib651 lib652 lib653 lib654 lib655 \ + lib643 lib644 lib645 lib650 lib651 lib652 lib653 lib654 lib655 lib658 \ lib1156 \ lib1500 lib1501 lib1502 lib1503 lib1504 lib1505 lib1506 lib1507 lib1508 \ lib1509 lib1510 lib1511 lib1512 lib1513 lib1514 lib1515 lib1517 \ - lib1520 lib1521 lib1522 \ + lib1518 lib1520 lib1521 lib1522 \ lib1525 lib1526 lib1527 lib1528 lib1529 lib1530 lib1531 lib1532 lib1533 \ lib1534 lib1535 lib1536 lib1537 lib1538 \ lib1540 \ @@ -339,6 +339,10 @@ lib654_CPPFLAGS = $(AM_CPPFLAGS) lib655_SOURCES = lib655.c $(SUPPORTFILES) lib655_CPPFLAGS = $(AM_CPPFLAGS) +lib658_SOURCES = lib658.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS) +lib658_LDADD = $(TESTUTIL_LIBS) +lib658_CPPFLAGS = $(AM_CPPFLAGS) + lib1500_SOURCES = lib1500.c $(SUPPORTFILES) $(TESTUTIL) lib1500_LDADD = $(TESTUTIL_LIBS) lib1500_CPPFLAGS = $(AM_CPPFLAGS) @@ -410,6 +414,9 @@ lib1515_CPPFLAGS = $(AM_CPPFLAGS) -DLIB1515 lib1517_SOURCES = lib1517.c $(SUPPORTFILES) lib1517_CPPFLAGS = $(AM_CPPFLAGS) -DLIB1517 +lib1518_SOURCES = lib1518.c $(SUPPORTFILES) +lib1518_CPPFLAGS = $(AM_CPPFLAGS) + lib1520_SOURCES = lib1520.c $(SUPPORTFILES) lib1520_CPPFLAGS = $(AM_CPPFLAGS) -DLIB1520 diff --git a/tests/libtest/chkdecimalpoint.c b/tests/libtest/chkdecimalpoint.c index b5f5070c..7bb77150 100644 --- a/tests/libtest/chkdecimalpoint.c +++ b/tests/libtest/chkdecimalpoint.c @@ -33,7 +33,7 @@ int main(void) int chars; setlocale(LC_NUMERIC, ""); - chars = snprintf(zero, TOTAL_STR_LEN, "%.1f", 0.0); + chars = msnprintf(zero, TOTAL_STR_LEN, "%.1f", 0.0); if((chars == (TOTAL_STR_LEN - 1)) && (strcmp(zero, "0.0") == 0)) return 0; else diff --git a/tests/libtest/first.c b/tests/libtest/first.c index 86d84cac..405e6f84 100644 --- a/tests/libtest/first.c +++ b/tests/libtest/first.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, 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 @@ -124,7 +124,7 @@ char *hexdump(const unsigned char *buffer, size_t len) if(len > 200) return NULL; for(i = 0; i<len; i++, p += 3) - snprintf(p, 4, "%02x ", buffer[i]); + msnprintf(p, 4, "%02x ", buffer[i]); return dump; } diff --git a/tests/libtest/lib1156.c b/tests/libtest/lib1156.c index 63348de7..cb8878c2 100644 --- a/tests/libtest/lib1156.c +++ b/tests/libtest/lib1156.c @@ -91,7 +91,7 @@ static int onetest(CURL *curl, const char *url, const testparams *p) replyselector = p->flags & F_CONTENTRANGE? 1: 0; if(p->flags & F_HTTP416) replyselector += 2; - snprintf(urlbuf, sizeof(urlbuf), "%s%04u", url, replyselector); + msnprintf(urlbuf, sizeof(urlbuf), "%s%04u", url, replyselector); test_setopt(curl, CURLOPT_URL, urlbuf); test_setopt(curl, CURLOPT_RESUME_FROM, (p->flags & F_RESUME)? 3: 0); test_setopt(curl, CURLOPT_RANGE, !(p->flags & F_RESUME)? diff --git a/tests/libtest/lib1502.c b/tests/libtest/lib1502.c index bd7c7c86..6bde00a8 100644 --- a/tests/libtest/lib1502.c +++ b/tests/libtest/lib1502.c @@ -50,8 +50,8 @@ int test(char *URL) /* DNS cache injection */ struct curl_slist *dns_cache_list; - snprintf(redirect, sizeof(redirect), "google.com:%s:%s", libtest_arg2, - libtest_arg3); + msnprintf(redirect, sizeof(redirect), "google.com:%s:%s", libtest_arg2, + libtest_arg3); start_test_timing(); diff --git a/tests/libtest/lib1506.c b/tests/libtest/lib1506.c index d456bc95..1d5e8de4 100644 --- a/tests/libtest/lib1506.c +++ b/tests/libtest/lib1506.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 2013, 2017, Linus Nielsen Feltzing <linus@haxx.se> + * Copyright (C) 2013 - 2018, Linus Nielsen Feltzing <linus@haxx.se> * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -46,8 +46,8 @@ int test(char *URL) /* Create fake DNS entries for serverX.example.com for all handles */ for(i = 0; i < NUM_HANDLES; i++) { - snprintf(dnsentry, sizeof(dnsentry), "server%d.example.com:%s:%s", - i + 1, port, address); + msnprintf(dnsentry, sizeof(dnsentry), "server%d.example.com:%s:%s", + i + 1, port, address); printf("%s\n", dnsentry); slist2 = curl_slist_append(slist, dnsentry); if(!slist2) { @@ -70,9 +70,9 @@ int test(char *URL) /* get an easy handle */ easy_init(curl[i]); /* specify target */ - snprintf(target_url, sizeof(target_url), - "http://server%d.example.com:%s/path/1506%04i", - i + 1, port, i + 1); + msnprintf(target_url, sizeof(target_url), + "http://server%d.example.com:%s/path/1506%04i", + i + 1, port, i + 1); target_url[sizeof(target_url) - 1] = '\0'; easy_setopt(curl[i], CURLOPT_URL, target_url); /* go verbose */ diff --git a/tests/libtest/lib1510.c b/tests/libtest/lib1510.c index d72749b2..4c7b670a 100644 --- a/tests/libtest/lib1510.c +++ b/tests/libtest/lib1510.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 2013, 2017, Linus Nielsen Feltzing <linus@haxx.se> + * Copyright (C) 2013 - 2018, Linus Nielsen Feltzing <linus@haxx.se> * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -44,8 +44,8 @@ int test(char *URL) /* Create fake DNS entries for serverX.example.com for all handles */ for(i = 0; i < NUM_URLS; i++) { - snprintf(dnsentry, sizeof(dnsentry), "server%d.example.com:%s:%s", i + 1, - port, address); + msnprintf(dnsentry, sizeof(dnsentry), "server%d.example.com:%s:%s", i + 1, + port, address); printf("%s\n", dnsentry); slist2 = curl_slist_append(slist, dnsentry); if(!slist2) { @@ -74,9 +74,9 @@ int test(char *URL) /* get NUM_HANDLES easy handles */ for(i = 0; i < NUM_URLS; i++) { /* specify target */ - snprintf(target_url, sizeof(target_url), - "http://server%d.example.com:%s/path/1510%04i", - i + 1, port, i + 1); + msnprintf(target_url, sizeof(target_url), + "http://server%d.example.com:%s/path/1510%04i", + i + 1, port, i + 1); target_url[sizeof(target_url) - 1] = '\0'; easy_setopt(curl, CURLOPT_URL, target_url); diff --git a/tests/libtest/lib1512.c b/tests/libtest/lib1512.c index 1c257895..0b71ad3f 100644 --- a/tests/libtest/lib1512.c +++ b/tests/libtest/lib1512.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 2013 - 2017, Linus Nielsen Feltzing <linus@haxx.se> + * Copyright (C) 2013 - 2018, Linus Nielsen Feltzing <linus@haxx.se> * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -49,8 +49,8 @@ int test(char *URL) return TEST_ERR_MAJOR_BAD; } - snprintf(dnsentry, sizeof(dnsentry), "server.example.curl:%s:%s", - port, address); + msnprintf(dnsentry, sizeof(dnsentry), "server.example.curl:%s:%s", + port, address); printf("%s\n", dnsentry); slist = curl_slist_append(slist, dnsentry); @@ -59,9 +59,9 @@ int test(char *URL) /* get an easy handle */ easy_init(curl[i]); /* specify target */ - snprintf(target_url, sizeof(target_url), - "http://server.example.curl:%s/path/1512%04i", - port, i + 1); + msnprintf(target_url, sizeof(target_url), + "http://server.example.curl:%s/path/1512%04i", + port, i + 1); target_url[sizeof(target_url) - 1] = '\0'; easy_setopt(curl[i], CURLOPT_URL, target_url); /* go verbose */ diff --git a/tests/libtest/lib1515.c b/tests/libtest/lib1515.c index 39bccc59..c72554a3 100644 --- a/tests/libtest/lib1515.c +++ b/tests/libtest/lib1515.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, 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 @@ -123,8 +123,8 @@ int test(char *URL) int i; int count = 2; - snprintf(dns_entry, sizeof(dns_entry), "testserver.example.com:%s:%s", - port, address); + msnprintf(dns_entry, sizeof(dns_entry), "testserver.example.com:%s:%s", + port, address); start_test_timing(); @@ -133,8 +133,8 @@ int test(char *URL) for(i = 1; i <= count; i++) { char target_url[256]; - snprintf(target_url, sizeof(target_url), - "http://testserver.example.com:%s/%s%04d", port, path, i); + msnprintf(target_url, sizeof(target_url), + "http://testserver.example.com:%s/%s%04d", port, path, i); /* second request must succeed like the first one */ res = do_one_request(multi, target_url, dns_entry); diff --git a/tests/libtest/lib1518.c b/tests/libtest/lib1518.c new file mode 100644 index 00000000..1751b583 --- /dev/null +++ b/tests/libtest/lib1518.c @@ -0,0 +1,74 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2018, 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 "memdebug.h" + +/* Test inspired by github issue 3340 */ + +int test(char *URL) +{ + CURL *curl; + CURLcode res = CURLE_OK; + long curlResponseCode; + long curlRedirectCount; + char *effectiveUrl = NULL; + char *redirectUrl = NULL; + + curl = curl_easy_init(); + if(!curl) { + fprintf(stderr, "curl_easy_init() failed\n"); + curl_global_cleanup(); + return TEST_ERR_MAJOR_BAD; + } + + test_setopt(curl, CURLOPT_URL, URL); + /* just to make it explicit and visible in this test: */ + test_setopt(curl, CURLOPT_FOLLOWLOCATION, 0L); + + /* Perform the request, res will get the return code */ + res = curl_easy_perform(curl); + + curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &curlResponseCode); + curl_easy_getinfo(curl, CURLINFO_REDIRECT_COUNT, &curlRedirectCount); + curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &effectiveUrl); + curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &redirectUrl); + + printf("res: %d\n" + "status: %d\n" + "redirects: %d\n" + "effectiveurl: %s\n" + "redirecturl: %s\n", + (int)res, + (int)curlResponseCode, + (int)curlRedirectCount, + effectiveUrl, + redirectUrl); + +test_cleanup: + + /* always cleanup */ + curl_easy_cleanup(curl); + curl_global_cleanup(); + + return res; +} diff --git a/tests/libtest/lib1529.c b/tests/libtest/lib1529.c index c63a109b..8d2210e2 100644 --- a/tests/libtest/lib1529.c +++ b/tests/libtest/lib1529.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, 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 @@ -29,7 +29,8 @@ int test(char *URL) CURL *curl = NULL; CURLcode res = CURLE_FAILED_INIT; char bURL[512]; - snprintf(bURL, sizeof(bURL), "%s HTTP/1.1\r\nGET http://1529.com/1529", URL); + msnprintf(bURL, sizeof(bURL), + "%s HTTP/1.1\r\nGET http://1529.com/1529", URL); if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); diff --git a/tests/libtest/lib1560.c b/tests/libtest/lib1560.c index e0faa12b..7ae1025b 100644 --- a/tests/libtest/lib1560.c +++ b/tests/libtest/lib1560.c @@ -67,10 +67,10 @@ static int checkparts(CURLU *u, const char *in, const char *wanted, size_t n; rc = curl_url_get(u, parts[i].part, &p, getflags); if(!rc && p) { - snprintf(bufp, len, "%s%s", buf[0]?" | ":"", p); + msnprintf(bufp, len, "%s%s", buf[0]?" | ":"", p); } else - snprintf(bufp, len, "%s[%d]", buf[0]?" | ":"", (int)rc); + msnprintf(bufp, len, "%s[%d]", buf[0]?" | ":"", (int)rc); n = strlen(bufp); bufp += n; @@ -128,6 +128,29 @@ struct querycase { }; static struct testcase get_parts_list[] ={ +#ifdef WIN32 + {"file:/C:\\programs\\foo", + "file | [11] | [12] | [13] | [14] | [15] | C:\\programs\\foo | [16] | [17]", + CURLU_DEFAULT_SCHEME, 0, CURLUE_OK}, + {"file://C:\\programs\\foo", + "file | [11] | [12] | [13] | [14] | [15] | C:\\programs\\foo | [16] | [17]", + CURLU_DEFAULT_SCHEME, 0, CURLUE_OK}, + {"file:///C:\\programs\\foo", + "file | [11] | [12] | [13] | [14] | [15] | C:\\programs\\foo | [16] | [17]", + CURLU_DEFAULT_SCHEME, 0, CURLUE_OK}, +#endif + {"boing:80", + "https | [11] | [12] | [13] | boing | 80 | / | [16] | [17]", + CURLU_DEFAULT_SCHEME, 0, CURLUE_OK}, + {"http://[fd00:a41::50]:8080", + "http | [11] | [12] | [13] | [fd00:a41::50] | 8080 | / | [16] | [17]", + CURLU_DEFAULT_SCHEME, 0, CURLUE_OK}, + {"http://[fd00:a41::50]/", + "http | [11] | [12] | [13] | [fd00:a41::50] | [15] | / | [16] | [17]", + CURLU_DEFAULT_SCHEME, 0, CURLUE_OK}, + {"http://[fd00:a41::50]", + "http | [11] | [12] | [13] | [fd00:a41::50] | [15] | / | [16] | [17]", + CURLU_DEFAULT_SCHEME, 0, CURLUE_OK}, {"https://[::1%252]:1234", "https | [11] | [12] | [13] | [::1%252] | 1234 | / | [16] | [17]", CURLU_DEFAULT_SCHEME, 0, CURLUE_OK}, @@ -700,7 +723,7 @@ static int get_parts(void) static struct querycase append_list[] = { {"HTTP://test/?s", "name=joe\x02", "http://test/?s&name=joe%02", 0, CURLU_URLENCODE, CURLUE_OK}, - {"HTTP://test/?size=2#f", "name=joe=", "http://test/?size=2&name=joe=#f", + {"HTTP://test/?size=2#f", "name=joe=", "http://test/?size=2&name=joe%3d#f", 0, CURLU_URLENCODE, CURLUE_OK}, {"HTTP://test/?size=2#f", "name=joe doe", "http://test/?size=2&name=joe+doe#f", diff --git a/tests/libtest/lib1900.c b/tests/libtest/lib1900.c index cf55fb33..1e10bdf3 100644 --- a/tests/libtest/lib1900.c +++ b/tests/libtest/lib1900.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 2013 - 2017, Linus Nielsen Feltzing, <linus@haxx.se> + * Copyright (C) 2013 - 2018, Linus Nielsen Feltzing, <linus@haxx.se> * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -113,7 +113,7 @@ static void setup_handle(char *base_url, CURLM *m, int handlenum) { char urlbuf[256]; - snprintf(urlbuf, sizeof(urlbuf), "%s%s", base_url, urlstring[handlenum]); + msnprintf(urlbuf, sizeof(urlbuf), "%s%s", base_url, urlstring[handlenum]); curl_easy_setopt(handles[handlenum], CURLOPT_URL, urlbuf); curl_easy_setopt(handles[handlenum], CURLOPT_VERBOSE, 1L); curl_easy_setopt(handles[handlenum], CURLOPT_FAILONERROR, 1L); diff --git a/tests/libtest/lib518.c b/tests/libtest/lib518.c index 81c5a5fa..1a3091fc 100644 --- a/tests/libtest/lib518.c +++ b/tests/libtest/lib518.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, 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 @@ -55,10 +55,10 @@ static char msgbuff[256]; static void store_errmsg(const char *msg, int err) { if(!err) - snprintf(msgbuff, sizeof(msgbuff), "%s", msg); + msnprintf(msgbuff, sizeof(msgbuff), "%s", msg); else - snprintf(msgbuff, sizeof(msgbuff), "%s, errno %d, %s", msg, - err, strerror(err)); + msnprintf(msgbuff, sizeof(msgbuff), "%s, errno %d, %s", msg, + err, strerror(err)); } static void close_file_descriptors(void) @@ -132,7 +132,7 @@ static int rlimit(int keep_open) strcpy(strbuff, "INFINITY"); else #endif - snprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_cur); + msnprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_cur); fprintf(stderr, "initial soft limit: %s\n", strbuff); #ifdef RLIM_INFINITY @@ -140,7 +140,7 @@ static int rlimit(int keep_open) strcpy(strbuff, "INFINITY"); else #endif - snprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_max); + msnprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_max); fprintf(stderr, "initial hard limit: %s\n", strbuff); /* show our constants */ @@ -198,7 +198,7 @@ static int rlimit(int keep_open) strcpy(strbuff, "INFINITY"); else #endif - snprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_cur); + msnprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_cur); fprintf(stderr, "current soft limit: %s\n", strbuff); #ifdef RLIM_INFINITY @@ -206,7 +206,7 @@ static int rlimit(int keep_open) strcpy(strbuff, "INFINITY"); else #endif - snprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_max); + msnprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_max); fprintf(stderr, "current hard limit: %s\n", strbuff); } /* (rl.rlim_cur != rl.rlim_max) */ @@ -233,10 +233,10 @@ static int rlimit(int keep_open) (rl.rlim_cur != RLIM_INFINITY) && #endif (rl.rlim_cur <= num_open.rlim_cur)) { - snprintf(strbuff2, sizeof(strbuff2), fmt, rl.rlim_cur); - snprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_cur); - snprintf(strbuff, sizeof(strbuff), "fds needed %s > system limit %s", - strbuff1, strbuff2); + msnprintf(strbuff2, sizeof(strbuff2), fmt, rl.rlim_cur); + msnprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_cur); + msnprintf(strbuff, sizeof(strbuff), "fds needed %s > system limit %s", + strbuff1, strbuff2); store_errmsg(strbuff, 0); fprintf(stderr, "%s\n", msgbuff); return -4; @@ -257,7 +257,7 @@ static int rlimit(int keep_open) nitems = 0x40000; do { num_open.rlim_max = sizeof(*memchunk) * (size_t)nitems; - snprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max); + msnprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max); fprintf(stderr, "allocating memchunk %s byte array\n", strbuff); memchunk = malloc(sizeof(*memchunk) * (size_t)nitems); if(!memchunk) { @@ -285,9 +285,9 @@ static int rlimit(int keep_open) /* verify that we won't overflow size_t in malloc() */ if((size_t)(num_open.rlim_max) > ((size_t)-1) / sizeof(*fd)) { - snprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_max); - snprintf(strbuff, sizeof(strbuff), "unable to allocate an array for %s " - "file descriptors, would overflow size_t", strbuff1); + msnprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_max); + msnprintf(strbuff, sizeof(strbuff), "unable to allocate an array for %s " + "file descriptors, would overflow size_t", strbuff1); store_errmsg(strbuff, 0); fprintf(stderr, "%s\n", msgbuff); free(memchunk); @@ -296,7 +296,7 @@ static int rlimit(int keep_open) /* allocate array for file descriptors */ - snprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max); + msnprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max); fprintf(stderr, "allocating array for %s file descriptors\n", strbuff); fd = malloc(sizeof(*fd) * (size_t)(num_open.rlim_max)); @@ -316,14 +316,14 @@ static int rlimit(int keep_open) num_open.rlim_cur++) fd[num_open.rlim_cur] = -1; - snprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max); + msnprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max); fprintf(stderr, "trying to open %s file descriptors\n", strbuff); /* open a dummy descriptor */ fd[0] = open(DEV_NULL, O_RDONLY); if(fd[0] < 0) { - snprintf(strbuff, sizeof(strbuff), "opening of %s failed", DEV_NULL); + msnprintf(strbuff, sizeof(strbuff), "opening of %s failed", DEV_NULL); store_errmsg(strbuff, errno); fprintf(stderr, "%s\n", msgbuff); free(fd); @@ -344,20 +344,20 @@ static int rlimit(int keep_open) fd[num_open.rlim_cur] = -1; - snprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_cur); - snprintf(strbuff, sizeof(strbuff), "dup() attempt %s failed", strbuff1); + msnprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_cur); + msnprintf(strbuff, sizeof(strbuff), "dup() attempt %s failed", strbuff1); fprintf(stderr, "%s\n", strbuff); - snprintf(strbuff1, sizeof(strbuff), fmt, num_open.rlim_cur); - snprintf(strbuff, sizeof(strbuff), "fds system limit seems close to %s", + msnprintf(strbuff1, sizeof(strbuff), fmt, num_open.rlim_cur); + msnprintf(strbuff, sizeof(strbuff), "fds system limit seems close to %s", strbuff1); fprintf(stderr, "%s\n", strbuff); num_open.rlim_max = NUM_NEEDED; - snprintf(strbuff2, sizeof(strbuff2), fmt, num_open.rlim_max); - snprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_cur); - snprintf(strbuff, sizeof(strbuff), "fds needed %s > system limit %s", + msnprintf(strbuff2, sizeof(strbuff2), fmt, num_open.rlim_max); + msnprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_cur); + msnprintf(strbuff, sizeof(strbuff), "fds needed %s > system limit %s", strbuff2, strbuff1); store_errmsg(strbuff, 0); fprintf(stderr, "%s\n", msgbuff); @@ -375,7 +375,7 @@ static int rlimit(int keep_open) } - snprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max); + msnprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max); fprintf(stderr, "%s file descriptors open\n", strbuff); #if !defined(HAVE_POLL_FINE) && \ @@ -395,7 +395,7 @@ static int rlimit(int keep_open) num_open.rlim_cur = FD_SETSIZE - SAFETY_MARGIN; if(num_open.rlim_max > num_open.rlim_cur) { - snprintf(strbuff, sizeof(strbuff), "select limit is FD_SETSIZE %d", + msnprintf(strbuff, sizeof(strbuff), "select limit is FD_SETSIZE %d", FD_SETSIZE); store_errmsg(strbuff, 0); fprintf(stderr, "%s\n", msgbuff); @@ -410,7 +410,7 @@ static int rlimit(int keep_open) rl.rlim_cur++) { if((fd[rl.rlim_cur] > 0) && ((unsigned int)fd[rl.rlim_cur] > num_open.rlim_cur)) { - snprintf(strbuff, sizeof(strbuff), "select limit is FD_SETSIZE %d", + msnprintf(strbuff, sizeof(strbuff), "select limit is FD_SETSIZE %d", FD_SETSIZE); store_errmsg(strbuff, 0); fprintf(stderr, "%s\n", msgbuff); @@ -432,12 +432,12 @@ static int rlimit(int keep_open) */ if(!fopen_works()) { - snprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_max); - snprintf(strbuff, sizeof(strbuff), + msnprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_max); + msnprintf(strbuff, sizeof(strbuff), "fopen fails with %s fds open()", strbuff1); fprintf(stderr, "%s\n", msgbuff); - snprintf(strbuff, sizeof(strbuff), + msnprintf(strbuff, sizeof(strbuff), "fopen fails with lots of fds open()"); store_errmsg(strbuff, 0); close_file_descriptors(); diff --git a/tests/libtest/lib530.c b/tests/libtest/lib530.c index 7b71fa5e..8581303a 100644 --- a/tests/libtest/lib530.c +++ b/tests/libtest/lib530.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, 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 @@ -53,7 +53,7 @@ int test(char *URL) /* get an easy handle */ easy_init(curl[i]); /* specify target */ - snprintf(target_url, sizeof(target_url), "%s%04i", URL, i + 1); + msnprintf(target_url, sizeof(target_url), "%s%04i", URL, i + 1); target_url[sizeof(target_url) - 1] = '\0'; easy_setopt(curl[i], CURLOPT_URL, target_url); /* go verbose */ diff --git a/tests/libtest/lib537.c b/tests/libtest/lib537.c index bdc2e62e..e8fb16a4 100644 --- a/tests/libtest/lib537.c +++ b/tests/libtest/lib537.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, 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 @@ -56,10 +56,10 @@ static char msgbuff[256]; static void store_errmsg(const char *msg, int err) { if(!err) - snprintf(msgbuff, sizeof(msgbuff), "%s", msg); + msnprintf(msgbuff, sizeof(msgbuff), "%s", msg); else - snprintf(msgbuff, sizeof(msgbuff), "%s, errno %d, %s", msg, err, - strerror(err)); + msnprintf(msgbuff, sizeof(msgbuff), "%s, errno %d, %s", msg, err, + strerror(err)); } static void close_file_descriptors(void) @@ -133,7 +133,7 @@ static int rlimit(int keep_open) strcpy(strbuff, "INFINITY"); else #endif - snprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_cur); + msnprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_cur); fprintf(stderr, "initial soft limit: %s\n", strbuff); #ifdef RLIM_INFINITY @@ -141,7 +141,7 @@ static int rlimit(int keep_open) strcpy(strbuff, "INFINITY"); else #endif - snprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_max); + msnprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_max); fprintf(stderr, "initial hard limit: %s\n", strbuff); /* @@ -193,7 +193,7 @@ static int rlimit(int keep_open) strcpy(strbuff, "INFINITY"); else #endif - snprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_cur); + msnprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_cur); fprintf(stderr, "current soft limit: %s\n", strbuff); #ifdef RLIM_INFINITY @@ -201,7 +201,7 @@ static int rlimit(int keep_open) strcpy(strbuff, "INFINITY"); else #endif - snprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_max); + msnprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_max); fprintf(stderr, "current hard limit: %s\n", strbuff); } /* (rl.rlim_cur != rl.rlim_max) */ @@ -231,7 +231,7 @@ static int rlimit(int keep_open) nitems = 0x40000; do { num_open.rlim_max = sizeof(*memchunk) * nitems; - snprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max); + msnprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max); fprintf(stderr, "allocating memchunk %s byte array\n", strbuff); memchunk = malloc(sizeof(*memchunk) * (size_t)nitems); if(!memchunk) { @@ -274,9 +274,9 @@ static int rlimit(int keep_open) /* verify that we won't overflow size_t in malloc() */ if((size_t)(num_open.rlim_max) > ((size_t)-1) / sizeof(*fd)) { - snprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_max); - snprintf(strbuff, sizeof(strbuff), "unable to allocate an array for %s " - "file descriptors, would overflow size_t", strbuff1); + msnprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_max); + msnprintf(strbuff, sizeof(strbuff), "unable to allocate an array for %s " + "file descriptors, would overflow size_t", strbuff1); store_errmsg(strbuff, 0); fprintf(stderr, "%s\n", msgbuff); free(memchunk); @@ -286,7 +286,7 @@ static int rlimit(int keep_open) /* allocate array for file descriptors */ do { - snprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max); + msnprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max); fprintf(stderr, "allocating array for %s file descriptors\n", strbuff); fd = malloc(sizeof(*fd) * (size_t)(num_open.rlim_max)); if(!fd) { @@ -310,14 +310,14 @@ static int rlimit(int keep_open) num_open.rlim_cur++) fd[num_open.rlim_cur] = -1; - snprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max); + msnprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max); fprintf(stderr, "trying to open %s file descriptors\n", strbuff); /* open a dummy descriptor */ fd[0] = open(DEV_NULL, O_RDONLY); if(fd[0] < 0) { - snprintf(strbuff, sizeof(strbuff), "opening of %s failed", DEV_NULL); + msnprintf(strbuff, sizeof(strbuff), "opening of %s failed", DEV_NULL); store_errmsg(strbuff, errno); fprintf(stderr, "%s\n", msgbuff); free(fd); @@ -338,21 +338,21 @@ static int rlimit(int keep_open) fd[num_open.rlim_cur] = -1; - snprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_cur); - snprintf(strbuff, sizeof(strbuff), "dup() attempt %s failed", strbuff1); + msnprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_cur); + msnprintf(strbuff, sizeof(strbuff), "dup() attempt %s failed", strbuff1); fprintf(stderr, "%s\n", strbuff); - snprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_cur); - snprintf(strbuff, sizeof(strbuff), "fds system limit seems close to %s", - strbuff1); + msnprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_cur); + msnprintf(strbuff, sizeof(strbuff), "fds system limit seems close to %s", + strbuff1); fprintf(stderr, "%s\n", strbuff); num_open.rlim_max = num_open.rlim_cur - SAFETY_MARGIN; num_open.rlim_cur -= num_open.rlim_max; - snprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_cur); - snprintf(strbuff, sizeof(strbuff), "closing %s file descriptors", - strbuff1); + msnprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_cur); + msnprintf(strbuff, sizeof(strbuff), "closing %s file descriptors", + strbuff1); fprintf(stderr, "%s\n", strbuff); for(num_open.rlim_cur = num_open.rlim_max; @@ -362,7 +362,7 @@ static int rlimit(int keep_open) fd[num_open.rlim_cur] = -1; } - snprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max); + msnprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max); fprintf(stderr, "shrinking array for %s file descriptors\n", strbuff); /* we don't care if we can't shrink it */ @@ -379,7 +379,7 @@ static int rlimit(int keep_open) } - snprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max); + msnprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max); fprintf(stderr, "%s file descriptors open\n", strbuff); #if !defined(HAVE_POLL_FINE) && \ @@ -399,8 +399,8 @@ static int rlimit(int keep_open) num_open.rlim_cur = FD_SETSIZE - SAFETY_MARGIN; if(num_open.rlim_max > num_open.rlim_cur) { - snprintf(strbuff, sizeof(strbuff), "select limit is FD_SETSIZE %d", - FD_SETSIZE); + msnprintf(strbuff, sizeof(strbuff), "select limit is FD_SETSIZE %d", + FD_SETSIZE); store_errmsg(strbuff, 0); fprintf(stderr, "%s\n", msgbuff); close_file_descriptors(); @@ -414,8 +414,8 @@ static int rlimit(int keep_open) rl.rlim_cur++) { if((fd[rl.rlim_cur] > 0) && ((unsigned int)fd[rl.rlim_cur] > num_open.rlim_cur)) { - snprintf(strbuff, sizeof(strbuff), "select limit is FD_SETSIZE %d", - FD_SETSIZE); + msnprintf(strbuff, sizeof(strbuff), "select limit is FD_SETSIZE %d", + FD_SETSIZE); store_errmsg(strbuff, 0); fprintf(stderr, "%s\n", msgbuff); close_file_descriptors(); @@ -436,11 +436,11 @@ static int rlimit(int keep_open) */ if(!fopen_works()) { - snprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_max); - snprintf(strbuff, sizeof(strbuff), "fopen fails with %s fds open", - strbuff1); + msnprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_max); + msnprintf(strbuff, sizeof(strbuff), "fopen fails with %s fds open", + strbuff1); fprintf(stderr, "%s\n", msgbuff); - snprintf(strbuff, sizeof(strbuff), "fopen fails with lots of fds open"); + msnprintf(strbuff, sizeof(strbuff), "fopen fails with lots of fds open"); store_errmsg(strbuff, 0); close_file_descriptors(); free(memchunk); diff --git a/tests/libtest/lib540.c b/tests/libtest/lib540.c index ff8a9b05..a52d8c50 100644 --- a/tests/libtest/lib540.c +++ b/tests/libtest/lib540.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, 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 @@ -198,7 +198,7 @@ int test(char *URL) if(test_argc < 4) return 99; - snprintf(buffer, sizeof(buffer), "Host: %s", HOST); + msnprintf(buffer, sizeof(buffer), "Host: %s", HOST); /* now add a custom Host: header */ headers = curl_slist_append(headers, buffer); diff --git a/tests/libtest/lib553.c b/tests/libtest/lib553.c index c06561e1..95b5ac39 100644 --- a/tests/libtest/lib553.c +++ b/tests/libtest/lib553.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, 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 @@ -75,7 +75,7 @@ int test(char *URL) } for(i = 0; i < NUM_HEADERS; i++) { - int len = snprintf(buf, sizeof(buf), "Header%d: ", i); + int len = msnprintf(buf, sizeof(buf), "Header%d: ", i); memset(&buf[len], 'A', SIZE_HEADERS); buf[len + SIZE_HEADERS] = 0; /* zero terminate */ hl = curl_slist_append(headerlist, buf); diff --git a/tests/libtest/lib658.c b/tests/libtest/lib658.c new file mode 100644 index 00000000..98e0db4b --- /dev/null +++ b/tests/libtest/lib658.c @@ -0,0 +1,76 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2011, 2018, 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" + +/* + * Get a single URL without select(). + */ + +int test(char *URL) +{ + CURL *handle = NULL; + CURLcode res = 0; + CURLU *urlp = NULL; + CURLUcode uc = 0; + + global_init(CURL_GLOBAL_ALL); + easy_init(handle); + + urlp = curl_url(); + + if(!urlp) { + fprintf(stderr, "problem init URL api."); + goto test_cleanup; + } + + uc = curl_url_set(urlp, CURLUPART_URL, URL, 0); + if(uc) { + fprintf(stderr, "problem setting CURLUPART_URL."); + goto test_cleanup; + } + + /* demonstrate override behavior */ + easy_setopt(handle, CURLOPT_URL, "http://www.example.com"); + + easy_setopt(handle, CURLOPT_CURLU, urlp); + easy_setopt(handle, CURLOPT_VERBOSE, 1L); + + res = curl_easy_perform(handle); + + if(res) { + fprintf(stderr, "%s:%d curl_easy_perform() failed with code %d (%s)\n", + __FILE__, __LINE__, res, curl_easy_strerror(res)); + goto test_cleanup; + } + +test_cleanup: + + curl_url_cleanup(urlp); + curl_easy_cleanup(handle); + curl_global_cleanup(); + + return res; +} diff --git a/tests/libtest/libauthretry.c b/tests/libtest/libauthretry.c index 8e348ad1..cfad6f3e 100644 --- a/tests/libtest/libauthretry.c +++ b/tests/libtest/libauthretry.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, 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 @@ -38,7 +38,7 @@ static CURLcode send_request(CURL *curl, const char *url, int seq, return CURLE_OUT_OF_MEMORY; } - snprintf(full_url, len, "%s%04d", url, seq); + msnprintf(full_url, len, "%s%04d", url, seq); fprintf(stderr, "Sending new request %d to %s with credential %s " "(auth %ld)\n", seq, full_url, userpwd, auth_scheme); test_setopt(curl, CURLOPT_URL, full_url); diff --git a/tests/libtest/libntlmconnect.c b/tests/libtest/libntlmconnect.c index e17b991a..426f6f24 100644 --- a/tests/libtest/libntlmconnect.c +++ b/tests/libtest/libntlmconnect.c @@ -135,11 +135,11 @@ int test(char *url) easy_init(easy[num_handles]); if(num_handles % 3 == 2) { - snprintf(full_url, urllen, "%s0200", url); + msnprintf(full_url, urllen, "%s0200", url); easy_setopt(easy[num_handles], CURLOPT_HTTPAUTH, CURLAUTH_NTLM); } else { - snprintf(full_url, urllen, "%s0100", url); + msnprintf(full_url, urllen, "%s0100", url); easy_setopt(easy[num_handles], CURLOPT_HTTPAUTH, CURLAUTH_BASIC); } easy_setopt(easy[num_handles], CURLOPT_FRESH_CONNECT, 1L); diff --git a/tests/libtest/stub_gssapi.c b/tests/libtest/stub_gssapi.c index aaa7796b..254a01b3 100644 --- a/tests/libtest/stub_gssapi.c +++ b/tests/libtest/stub_gssapi.c @@ -28,6 +28,11 @@ #include "stub_gssapi.h" +#define ENABLE_CURLX_PRINTF +/* make the curlx header define all printf() functions to use the curlx_* + versions instead */ +#include "curlx.h" /* from the private lib dir */ + #define MAX_CREDS_LENGTH 250 #define APPROX_TOKEN_LEN 250 @@ -202,8 +207,8 @@ OM_uint32 gss_init_sec_context(OM_uint32 *min, } /* Token format: creds:target:type:padding */ - used = snprintf(token, length, "%s:%s:%d:", creds, - (char *) target_name, ctx->sent); + used = msnprintf(token, length, "%s:%s:%d:", creds, + (char *) target_name, ctx->sent); if(used >= length) { free(token); diff --git a/tests/libtest/testtrace.c b/tests/libtest/testtrace.c index 0a98d006..2718ef93 100644 --- a/tests/libtest/testtrace.c +++ b/tests/libtest/testtrace.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, 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 @@ -108,8 +108,8 @@ int libtest_debug_cb(CURL *handle, curl_infotype type, } secs = epoch_offset + tv.tv_sec; now = localtime(&secs); /* not thread safe but we don't care */ - snprintf(timebuf, sizeof(timebuf), "%02d:%02d:%02d.%06ld ", - now->tm_hour, now->tm_min, now->tm_sec, (long)tv.tv_usec); + msnprintf(timebuf, sizeof(timebuf), "%02d:%02d:%02d.%06ld ", + now->tm_hour, now->tm_min, now->tm_sec, (long)tv.tv_usec); } switch(type) { diff --git a/tests/runtests.1 b/tests/runtests.1 index 5b63e563..a5a20876 100644 --- a/tests/runtests.1 +++ b/tests/runtests.1 @@ -20,7 +20,7 @@ .\" * .\" ************************************************************************** .\" -.TH runtests.pl 1 "May 05, 2017" "Curl 7.62.0" "runtests" +.TH runtests.pl 1 "May 05, 2017" "Curl 7.63.0" "runtests" .SH NAME runtests.pl \- run one or more test cases diff --git a/tests/runtests.pl b/tests/runtests.pl index 5dce3304..5b51d3e4 100755 --- a/tests/runtests.pl +++ b/tests/runtests.pl @@ -151,7 +151,7 @@ my $NEGTELNETPORT; # TELNET server port with negotiation my $srcdir = $ENV{'srcdir'} || '.'; my $CURL="../src/curl".exe_ext(); # what curl executable to run on the tests -my $VCURL="curl"; # what curl binary to use to verify the servers with +my $VCURL=$CURL; # what curl binary to use to verify the servers with # VCURL is handy to set to the system one when the one you # just built hangs or crashes and thus prevent verification my $DBGCURL=$CURL; #"../src/.libs/curl"; # alternative for debugging @@ -245,7 +245,6 @@ my $has_gnutls; # built with GnuTLS my $has_nss; # built with NSS my $has_yassl; # built with yassl my $has_polarssl; # built with polarssl -my $has_axtls; # built with axTLS my $has_winssl; # built with WinSSL (Secure Channel aka Schannel) my $has_darwinssl; # built with DarwinSSL (Secure Transport) my $has_boringssl; # built with BoringSSL @@ -793,7 +792,6 @@ sub verifyhttp { $flags .= "--verbose "; $flags .= "--globoff "; $flags .= "--unix-socket '$port_or_path' " if $ipvnum eq "unix"; - $flags .= "-1 " if($has_axtls); $flags .= "--insecure " if($proto eq 'https'); $flags .= "\"$proto://$ip:$port/${bonus}verifiedserver\""; @@ -2720,10 +2718,6 @@ sub checksystem { $has_sslpinning=1; $ssllib="polarssl"; } - elsif ($libcurl =~ /axtls/i) { - $has_axtls=1; - $ssllib="axTLS"; - } elsif ($libcurl =~ /securetransport/i) { $has_darwinssl=1; $has_sslpinning=1; @@ -3119,6 +3113,13 @@ sub subVariables { $$thing =~ s/%CURL/$CURL/g; $$thing =~ s/%PWD/$pwd/g; $$thing =~ s/%POSIX_PWD/$posix_pwd/g; + + my $file_pwd = $pwd; + if($file_pwd !~ /^\//) { + $file_pwd = "/$file_pwd"; + } + + $$thing =~ s/%FILE_PWD/$file_pwd/g; $$thing =~ s/%SRCDIR/$srcdir/g; $$thing =~ s/%USER/$USER/g; @@ -3278,11 +3279,6 @@ sub singletest { next; } } - elsif($1 eq "axTLS") { - if($has_axtls) { - next; - } - } elsif($1 eq "WinSSL") { if($has_winssl) { next; @@ -3456,11 +3452,6 @@ sub singletest { next; } } - elsif($1 eq "axTLS") { - if(!$has_axtls) { - next; - } - } elsif($1 eq "WinSSL") { if(!$has_winssl) { next; @@ -3887,8 +3878,6 @@ sub singletest { } elsif(!$tool) { # run curl, add suitable command line options - $cmd = "-1 ".$cmd if(exists $feature{"SSL"} && ($has_axtls)); - my $inc=""; if((!$cmdhash{'option'}) || ($cmdhash{'option'} !~ /no-include/)) { $inc = " --include"; diff --git a/tests/secureserver.pl b/tests/secureserver.pl index c897ee5f..969fb17b 100755 --- a/tests/secureserver.pl +++ b/tests/secureserver.pl @@ -264,6 +264,11 @@ if($stunnel_version < 400) { # if($stunnel_version >= 400) { $socketopt = "a:SO_REUSEADDR=1"; + if(($stunnel_version >= 534) && $tstunnel_windows) { + # SO_EXCLUSIVEADDRUSE is on by default on Vista or newer, + # but does not work together with SO_REUSEADDR being on. + $socketopt .= "\nsocket = a:SO_EXCLUSIVEADDRUSE=0"; + } $cmd = "$stunnel $conffile "; $cmd .= ">$logfile 2>&1"; # setup signal handler diff --git a/tests/server/fake_ntlm.c b/tests/server/fake_ntlm.c index ec127a8a..c6e36b6f 100644 --- a/tests/server/fake_ntlm.c +++ b/tests/server/fake_ntlm.c @@ -6,7 +6,7 @@ * \___|\___/|_| \_\_____| * * Copyright (C) 2010, Mandy Wu, <mandy.wu@intel.com> - * Copyright (C) 2011 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 2011 - 2018, 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 @@ -75,7 +75,7 @@ static char *printable(char *inbuf, size_t inlength) return NULL; if(!inlength) { - snprintf(&outbuf[0], outsize, "%s", NOTHING_STR); + msnprintf(&outbuf[0], outsize, "%s", NOTHING_STR); return outbuf; } @@ -97,7 +97,7 @@ static char *printable(char *inbuf, size_t inlength) o++; } else { - snprintf(&outbuf[o], outsize - o, HEX_FMT_STR, inbuf[i]); + msnprintf(&outbuf[o], outsize - o, HEX_FMT_STR, inbuf[i]); o += HEX_STR_LEN; } @@ -174,7 +174,7 @@ int main(int argc, char *argv[]) } /* logmsg cannot be used until this file name is set */ - snprintf(logfilename, sizeof(logfilename), LOGFILE, testnum); + msnprintf(logfilename, sizeof(logfilename), LOGFILE, testnum); serverlogfile = logfilename; logmsg("fake_ntlm (user: %s) (proto: %s) (domain: %s) (cached creds: %s)", diff --git a/tests/server/rtspd.c b/tests/server/rtspd.c index 0629d8a5..7563fd22 100644 --- a/tests/server/rtspd.c +++ b/tests/server/rtspd.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, 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 @@ -382,11 +382,11 @@ static int ProcessRequest(struct httprequest *req) char *filename; if((strlen(doc) + strlen(request)) < 200) - snprintf(logbuf, sizeof(logbuf), "Got request: %s %s %s/%d.%d", - request, doc, prot_str, prot_major, prot_minor); + msnprintf(logbuf, sizeof(logbuf), "Got request: %s %s %s/%d.%d", + request, doc, prot_str, prot_major, prot_minor); else - snprintf(logbuf, sizeof(logbuf), "Got a *HUGE* request %s/%d.%d", - prot_str, prot_major, prot_minor); + msnprintf(logbuf, sizeof(logbuf), "Got a *HUGE* request %s/%d.%d", + prot_str, prot_major, prot_minor); logmsg("%s", logbuf); if(!strncmp("/verifiedserver", ptr, 15)) { @@ -416,8 +416,8 @@ static int ProcessRequest(struct httprequest *req) else req->partno = 0; - snprintf(logbuf, sizeof(logbuf), "Requested test number %ld part %ld", - req->testno, req->partno); + msnprintf(logbuf, sizeof(logbuf), "Requested test number %ld part %ld", + req->testno, req->partno); logmsg("%s", logbuf); filename = test2file(req->testno); @@ -540,9 +540,9 @@ static int ProcessRequest(struct httprequest *req) else { if(sscanf(req->reqbuf, "CONNECT %" MAXDOCNAMELEN_TXT "s HTTP/%d.%d", doc, &prot_major, &prot_minor) == 3) { - snprintf(logbuf, sizeof(logbuf), - "Received a CONNECT %s HTTP/%d.%d request", - doc, prot_major, prot_minor); + msnprintf(logbuf, sizeof(logbuf), + "Received a CONNECT %s HTTP/%d.%d request", + doc, prot_major, prot_minor); logmsg("%s", logbuf); if(req->prot_version == 10) @@ -947,12 +947,12 @@ static int send_doc(curl_socket_t sock, struct httprequest *req) case DOCNUMBER_WERULEZ: /* we got a "friends?" question, reply back that we sure are */ logmsg("Identifying ourselves as friends"); - snprintf(msgbuf, sizeof(msgbuf), "RTSP_SERVER WE ROOLZ: %ld\r\n", - (long)getpid()); + msnprintf(msgbuf, sizeof(msgbuf), "RTSP_SERVER WE ROOLZ: %ld\r\n", + (long)getpid()); msglen = strlen(msgbuf); - snprintf(weare, sizeof(weare), - "HTTP/1.1 200 OK\r\nContent-Length: %zu\r\n\r\n%s", - msglen, msgbuf); + msnprintf(weare, sizeof(weare), + "HTTP/1.1 200 OK\r\nContent-Length: %zu\r\n\r\n%s", + msglen, msgbuf); buffer = weare; break; case DOCNUMBER_INTERNAL: @@ -985,7 +985,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req) char partbuf[80]="data"; FILE *stream; if(0 != req->partno) - snprintf(partbuf, sizeof(partbuf), "data%ld", req->partno); + msnprintf(partbuf, sizeof(partbuf), "data%ld", req->partno); stream = fopen(filename, "rb"); if(!stream) { diff --git a/tests/server/sockfilt.c b/tests/server/sockfilt.c index 86a1ff52..569be6f6 100644 --- a/tests/server/sockfilt.c +++ b/tests/server/sockfilt.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, 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 @@ -486,20 +486,20 @@ static void lograw(unsigned char *buffer, ssize_t len) for(i = 0; i<len; i++) { switch(ptr[i]) { case '\n': - snprintf(optr, left, "\\n"); + msnprintf(optr, left, "\\n"); width += 2; optr += 2; left -= 2; break; case '\r': - snprintf(optr, left, "\\r"); + msnprintf(optr, left, "\\r"); width += 2; optr += 2; left -= 2; break; default: - snprintf(optr, left, "%c", (ISGRAPH(ptr[i]) || - ptr[i] == 0x20) ?ptr[i]:'.'); + msnprintf(optr, left, "%c", (ISGRAPH(ptr[i]) || + ptr[i] == 0x20) ?ptr[i]:'.'); width++; optr++; left--; @@ -1062,9 +1062,9 @@ static bool juggle(curl_socket_t *sockfdp, else if(!memcmp("PORT", buffer, 4)) { /* Question asking us what PORT number we are listening to. Replies to PORT with "IPv[num]/[port]" */ - snprintf((char *)buffer, sizeof(buffer), "%s/%hu\n", ipv_inuse, port); + msnprintf((char *)buffer, sizeof(buffer), "%s/%hu\n", ipv_inuse, port); buffer_len = (ssize_t)strlen((char *)buffer); - snprintf(data, sizeof(data), "PORT\n%04zx\n", buffer_len); + msnprintf(data, sizeof(data), "PORT\n%04zx\n", buffer_len); if(!write_stdout(data, 10)) return FALSE; if(!write_stdout(buffer, buffer_len)) @@ -1155,7 +1155,7 @@ static bool juggle(curl_socket_t *sockfdp, nread_socket = sread(sockfd, buffer, sizeof(buffer)); if(nread_socket > 0) { - snprintf(data, sizeof(data), "DATA\n%04zx\n", nread_socket); + msnprintf(data, sizeof(data), "DATA\n%04zx\n", nread_socket); if(!write_stdout(data, 10)) return FALSE; if(!write_stdout(buffer, nread_socket)) diff --git a/tests/server/sws.c b/tests/server/sws.c index 8df4d76e..cf3d291d 100644 --- a/tests/server/sws.c +++ b/tests/server/sws.c @@ -509,11 +509,11 @@ static int ProcessRequest(struct httprequest *req) /* get the number after it */ if(ptr) { if((strlen(doc) + strlen(request)) < 400) - snprintf(logbuf, sizeof(logbuf), "Got request: %s %s HTTP/%d.%d", - request, doc, prot_major, prot_minor); + msnprintf(logbuf, sizeof(logbuf), "Got request: %s %s HTTP/%d.%d", + request, doc, prot_major, prot_minor); else - snprintf(logbuf, sizeof(logbuf), "Got a *HUGE* request HTTP/%d.%d", - prot_major, prot_minor); + msnprintf(logbuf, sizeof(logbuf), "Got a *HUGE* request HTTP/%d.%d", + prot_major, prot_minor); logmsg("%s", logbuf); if(!strncmp("/verifiedserver", ptr, 15)) { @@ -545,8 +545,8 @@ static int ProcessRequest(struct httprequest *req) if(req->testno) { - snprintf(logbuf, sizeof(logbuf), "Requested test number %ld part %ld", - req->testno, req->partno); + msnprintf(logbuf, sizeof(logbuf), "Requested test number %ld part %ld", + req->testno, req->partno); logmsg("%s", logbuf); /* find and parse <servercmd> for this test */ @@ -565,9 +565,9 @@ static int ProcessRequest(struct httprequest *req) doc, &prot_major, &prot_minor) == 3) { char *portp = NULL; - snprintf(logbuf, sizeof(logbuf), - "Received a CONNECT %s HTTP/%d.%d request", - doc, prot_major, prot_minor); + msnprintf(logbuf, sizeof(logbuf), + "Received a CONNECT %s HTTP/%d.%d request", + doc, prot_major, prot_minor); logmsg("%s", logbuf); req->connect_request = TRUE; @@ -645,9 +645,9 @@ static int ProcessRequest(struct httprequest *req) else req->partno = 0; - snprintf(logbuf, sizeof(logbuf), - "Requested test number %ld part %ld (from host name)", - req->testno, req->partno); + msnprintf(logbuf, sizeof(logbuf), + "Requested test number %ld part %ld (from host name)", + req->testno, req->partno); logmsg("%s", logbuf); } @@ -696,9 +696,9 @@ static int ProcessRequest(struct httprequest *req) else req->partno = 0; - snprintf(logbuf, sizeof(logbuf), - "Requested GOPHER test number %ld part %ld", - req->testno, req->partno); + msnprintf(logbuf, sizeof(logbuf), + "Requested GOPHER test number %ld part %ld", + req->testno, req->partno); logmsg("%s", logbuf); } } @@ -1117,14 +1117,14 @@ static int send_doc(curl_socket_t sock, struct httprequest *req) case DOCNUMBER_WERULEZ: /* we got a "friends?" question, reply back that we sure are */ logmsg("Identifying ourselves as friends"); - snprintf(msgbuf, sizeof(msgbuf), "WE ROOLZ: %ld\r\n", (long)getpid()); + msnprintf(msgbuf, sizeof(msgbuf), "WE ROOLZ: %ld\r\n", (long)getpid()); msglen = strlen(msgbuf); if(use_gopher) - snprintf(weare, sizeof(weare), "%s", msgbuf); + msnprintf(weare, sizeof(weare), "%s", msgbuf); else - snprintf(weare, sizeof(weare), - "HTTP/1.1 200 OK\r\nContent-Length: %zu\r\n\r\n%s", - msglen, msgbuf); + msnprintf(weare, sizeof(weare), + "HTTP/1.1 200 OK\r\nContent-Length: %zu\r\n\r\n%s", + msglen, msgbuf); buffer = weare; break; case DOCNUMBER_404: @@ -1145,9 +1145,9 @@ static int send_doc(curl_socket_t sock, struct httprequest *req) const char *section = req->connect_request?"connect":"data"; if(req->partno) - snprintf(partbuf, sizeof(partbuf), "%s%ld", section, req->partno); + msnprintf(partbuf, sizeof(partbuf), "%s%ld", section, req->partno); else - snprintf(partbuf, sizeof(partbuf), "%s", section); + msnprintf(partbuf, sizeof(partbuf), "%s", section); logmsg("Send response test%ld section <%s>", req->testno, partbuf); @@ -2118,7 +2118,7 @@ int main(int argc, char *argv[]) } } - snprintf(port_str, sizeof(port_str), "port %hu", port); + msnprintf(port_str, sizeof(port_str), "port %hu", port); #ifdef WIN32 win32_init(); diff --git a/tests/server/tftpd.c b/tests/server/tftpd.c index c00731fa..35419b0b 100644 --- a/tests/server/tftpd.c +++ b/tests/server/tftpd.c @@ -15,7 +15,7 @@ */ /* - * Copyright (c) 1983, 2016 Regents of the University of California. + * Copyright (c) 1983 Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -569,7 +569,7 @@ static ssize_t write_behind(struct testcase *test, int convert) if(!test->ofile) { char outfile[256]; - snprintf(outfile, sizeof(outfile), "log/upload.%ld", test->testno); + msnprintf(outfile, sizeof(outfile), "log/upload.%ld", test->testno); #ifdef WIN32 test->ofile = open(outfile, O_CREAT|O_RDWR|O_BINARY, 0777); #else @@ -1141,8 +1141,8 @@ static int validate_access(struct testcase *test, if(!strncmp("verifiedserver", filename, 14)) { char weare[128]; - size_t count = snprintf(weare, sizeof(weare), - "WE ROOLZ: %ld\r\n", (long)getpid()); + size_t count = msnprintf(weare, sizeof(weare), + "WE ROOLZ: %ld\r\n", (long)getpid()); logmsg("Are-we-friendly question received"); test->buffer = strdup(weare); @@ -1187,7 +1187,7 @@ static int validate_access(struct testcase *test, file = test2file(testno); if(0 != partno) - snprintf(partbuf, sizeof(partbuf), "data%ld", partno); + msnprintf(partbuf, sizeof(partbuf), "data%ld", partno); if(file) { FILE *stream = fopen(file, "rb"); diff --git a/tests/server/util.c b/tests/server/util.c index 07ef63ee..df1e35da 100644 --- a/tests/server/util.c +++ b/tests/server/util.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, 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 @@ -87,7 +87,7 @@ char *data_to_hex(char *data, size_t len) if((data[i] >= 0x20) && (data[i] < 0x7f)) *optr++ = *iptr++; else { - snprintf(optr, 4, "%%%02x", *iptr++); + msnprintf(optr, 4, "%%%02x", *iptr++); optr += 3; } } @@ -121,11 +121,12 @@ void logmsg(const char *msg, ...) sec = epoch_offset + tv.tv_sec; now = localtime(&sec); /* not thread safe but we don't care */ - snprintf(timebuf, sizeof(timebuf), "%02d:%02d:%02d.%06ld", - (int)now->tm_hour, (int)now->tm_min, (int)now->tm_sec, (long)tv.tv_usec); + msnprintf(timebuf, sizeof(timebuf), "%02d:%02d:%02d.%06ld", + (int)now->tm_hour, (int)now->tm_min, (int)now->tm_sec, + (long)tv.tv_usec); va_start(ap, msg); - vsnprintf(buffer, sizeof(buffer), msg, ap); + mvsnprintf(buffer, sizeof(buffer), msg, ap); va_end(ap); logfp = fopen(serverlogfile, "ab"); @@ -151,7 +152,7 @@ void win32_perror(const char *msg) if(!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, LANG_NEUTRAL, buf, sizeof(buf), NULL)) - snprintf(buf, sizeof(buf), "Unknown error %lu (%#lx)", err, err); + msnprintf(buf, sizeof(buf), "Unknown error %lu (%#lx)", err, err); if(msg) fprintf(stderr, "%s: ", msg); fprintf(stderr, "%s\n", buf); @@ -195,7 +196,7 @@ const char *path = "."; char *test2file(long testno) { static char filename[256]; - snprintf(filename, sizeof(filename), TEST_DATA_PATH, path, testno); + msnprintf(filename, sizeof(filename), TEST_DATA_PATH, path, testno); return filename; } diff --git a/tests/symbol-scan.pl b/tests/symbol-scan.pl index 5d570d8a..6706aa70 100755 --- a/tests/symbol-scan.pl +++ b/tests/symbol-scan.pl @@ -6,7 +6,7 @@ # | (__| |_| | _ <| |___ # \___|\___/|_| \_\_____| # -# Copyright (C) 2010-2011, Daniel Stenberg, <daniel@haxx.se>, et al. +# Copyright (C) 2010-2018, 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 @@ -53,6 +53,7 @@ my $i = ($ARGV[1]) ? "-I$ARGV[1] " : ''; my $h = "$root/include/curl/curl.h"; my $mh = "$root/include/curl/multi.h"; +my $ua = "$root/include/curl/urlapi.h"; my $verbose=0; my $summary=0; @@ -87,6 +88,7 @@ sub scanheader { scanheader($h); scanheader($mh); +scanheader($ua); open S, "<$root/docs/libcurl/symbols-in-versions"; while(<S>) { diff --git a/tests/testcurl.1 b/tests/testcurl.1 index 68aeb78b..748e3fae 100644 --- a/tests/testcurl.1 +++ b/tests/testcurl.1 @@ -20,7 +20,7 @@ .\" * .\" ************************************************************************** .\" -.TH testcurl.pl 1 "October 22, 2016" "Curl 7.62.0" "testcurl" +.TH testcurl.pl 1 "October 22, 2016" "Curl 7.63.0" "testcurl" .SH NAME testcurl.pl \- (automatically) test curl diff --git a/tests/unit/Makefile.inc b/tests/unit/Makefile.inc index 95d6cb44..8b1a6071 100644 --- a/tests/unit/Makefile.inc +++ b/tests/unit/Makefile.inc @@ -11,7 +11,7 @@ UNITPROGS = unit1300 unit1301 unit1302 unit1303 unit1304 unit1305 unit1307 \ unit1399 \ unit1600 unit1601 unit1602 unit1603 unit1604 unit1605 unit1606 unit1607 \ unit1608 unit1609 unit1620 \ - unit1650 unit1651 + unit1650 unit1651 unit1652 unit1653 unit1300_SOURCES = unit1300.c $(UNITFILES) unit1300_CPPFLAGS = $(AM_CPPFLAGS) @@ -105,3 +105,9 @@ unit1650_CPPFLAGS = $(AM_CPPFLAGS) unit1651_SOURCES = unit1651.c $(UNITFILES) unit1651_CPPFLAGS = $(AM_CPPFLAGS) + +unit1652_SOURCES = unit1652.c $(UNITFILES) +unit1652_CPPFLAGS = $(AM_CPPFLAGS) + +unit1653_SOURCES = unit1653.c $(UNITFILES) +unit1653_CPPFLAGS = $(AM_CPPFLAGS) diff --git a/tests/unit/unit1304.c b/tests/unit/unit1304.c index 83375f55..6d8334c9 100644 --- a/tests/unit/unit1304.c +++ b/tests/unit/unit1304.c @@ -47,6 +47,8 @@ static void unit_stop(void) UNITTEST_START int result; + bool login_changed; + bool password_changed; static const char * const filename1 = "log/netrc1304"; memcpy(filename, filename1, strlen(filename1)); @@ -54,7 +56,8 @@ UNITTEST_START /* * Test a non existent host in our netrc file. */ - result = Curl_parsenetrc("test.example.com", &login, &password, filename); + result = Curl_parsenetrc("test.example.com", &login, &password, + &login_changed, &password_changed, filename); fail_unless(result == 1, "Host not found should return 1"); abort_unless(password != NULL, "returned NULL!"); fail_unless(password[0] == 0, "password should not have been changed"); @@ -67,13 +70,16 @@ UNITTEST_START free(login); login = strdup("me"); abort_unless(login != NULL, "returned NULL!"); - result = Curl_parsenetrc("example.com", &login, &password, filename); - fail_unless(result == 0, "Host should be found"); + result = Curl_parsenetrc("example.com", &login, &password, + &login_changed, &password_changed, filename); + fail_unless(result == 0, "Host should have been found"); abort_unless(password != NULL, "returned NULL!"); fail_unless(password[0] == 0, "password should not have been changed"); + fail_unless(!password_changed, "password should not have been changed"); abort_unless(login != NULL, "returned NULL!"); fail_unless(strncmp(login, "me", 2) == 0, "login should not have been changed"); + fail_unless(!login_changed, "login should not have been changed"); /* * Test a non existent login and host in our netrc file. @@ -81,8 +87,9 @@ UNITTEST_START free(login); login = strdup("me"); abort_unless(login != NULL, "returned NULL!"); - result = Curl_parsenetrc("test.example.com", &login, &password, filename); - fail_unless(result == 1, "Host should be found"); + result = Curl_parsenetrc("test.example.com", &login, &password, + &login_changed, &password_changed, filename); + fail_unless(result == 1, "Host not found should return 1"); abort_unless(password != NULL, "returned NULL!"); fail_unless(password[0] == 0, "password should not have been changed"); abort_unless(login != NULL, "returned NULL!"); @@ -96,13 +103,16 @@ UNITTEST_START free(login); login = strdup("admi"); abort_unless(login != NULL, "returned NULL!"); - result = Curl_parsenetrc("example.com", &login, &password, filename); - fail_unless(result == 0, "Host should be found"); + result = Curl_parsenetrc("example.com", &login, &password, + &login_changed, &password_changed, filename); + fail_unless(result == 0, "Host should have been found"); abort_unless(password != NULL, "returned NULL!"); fail_unless(password[0] == 0, "password should not have been changed"); + fail_unless(!password_changed, "password should not have been changed"); abort_unless(login != NULL, "returned NULL!"); fail_unless(strncmp(login, "admi", 4) == 0, "login should not have been changed"); + fail_unless(!login_changed, "login should not have been changed"); /* * Test a non existent login (superstring of an existing one) @@ -111,13 +121,16 @@ UNITTEST_START free(login); login = strdup("adminn"); abort_unless(login != NULL, "returned NULL!"); - result = Curl_parsenetrc("example.com", &login, &password, filename); - fail_unless(result == 0, "Host should be found"); + result = Curl_parsenetrc("example.com", &login, &password, + &login_changed, &password_changed, filename); + fail_unless(result == 0, "Host should have been found"); abort_unless(password != NULL, "returned NULL!"); fail_unless(password[0] == 0, "password should not have been changed"); + fail_unless(!password_changed, "password should not have been changed"); abort_unless(login != NULL, "returned NULL!"); fail_unless(strncmp(login, "adminn", 6) == 0, "login should not have been changed"); + fail_unless(!login_changed, "login should not have been changed"); /* * Test for the first existing host in our netrc file @@ -126,13 +139,16 @@ UNITTEST_START free(login); login = strdup(""); abort_unless(login != NULL, "returned NULL!"); - result = Curl_parsenetrc("example.com", &login, &password, filename); + result = Curl_parsenetrc("example.com", &login, &password, + &login_changed, &password_changed, filename); fail_unless(result == 0, "Host should have been found"); abort_unless(password != NULL, "returned NULL!"); fail_unless(strncmp(password, "passwd", 6) == 0, "password should be 'passwd'"); + fail_unless(password_changed, "password should have been changed"); abort_unless(login != NULL, "returned NULL!"); fail_unless(strncmp(login, "admin", 5) == 0, "login should be 'admin'"); + fail_unless(login_changed, "login should have been changed"); /* * Test for the first existing host in our netrc file @@ -141,13 +157,16 @@ UNITTEST_START free(password); password = strdup(""); abort_unless(password != NULL, "returned NULL!"); - result = Curl_parsenetrc("example.com", &login, &password, filename); + result = Curl_parsenetrc("example.com", &login, &password, + &login_changed, &password_changed, filename); fail_unless(result == 0, "Host should have been found"); abort_unless(password != NULL, "returned NULL!"); fail_unless(strncmp(password, "passwd", 6) == 0, "password should be 'passwd'"); + fail_unless(password_changed, "password should have been changed"); abort_unless(login != NULL, "returned NULL!"); fail_unless(strncmp(login, "admin", 5) == 0, "login should be 'admin'"); + fail_unless(!login_changed, "login should not have been changed"); /* * Test for the second existing host in our netrc file @@ -159,13 +178,16 @@ UNITTEST_START free(login); login = strdup(""); abort_unless(login != NULL, "returned NULL!"); - result = Curl_parsenetrc("curl.example.com", &login, &password, filename); + result = Curl_parsenetrc("curl.example.com", &login, &password, + &login_changed, &password_changed, filename); fail_unless(result == 0, "Host should have been found"); abort_unless(password != NULL, "returned NULL!"); fail_unless(strncmp(password, "none", 4) == 0, "password should be 'none'"); + fail_unless(password_changed, "password should have been changed"); abort_unless(login != NULL, "returned NULL!"); fail_unless(strncmp(login, "none", 4) == 0, "login should be 'none'"); + fail_unless(login_changed, "login should have been changed"); /* * Test for the second existing host in our netrc file @@ -174,13 +196,16 @@ UNITTEST_START free(password); password = strdup(""); abort_unless(password != NULL, "returned NULL!"); - result = Curl_parsenetrc("curl.example.com", &login, &password, filename); + result = Curl_parsenetrc("curl.example.com", &login, &password, + &login_changed, &password_changed, filename); fail_unless(result == 0, "Host should have been found"); abort_unless(password != NULL, "returned NULL!"); fail_unless(strncmp(password, "none", 4) == 0, "password should be 'none'"); + fail_unless(password_changed, "password should have been changed"); abort_unless(login != NULL, "returned NULL!"); fail_unless(strncmp(login, "none", 4) == 0, "login should be 'none'"); + fail_unless(!login_changed, "login should not have been changed"); /* TODO: * Test over the size limit password / login! diff --git a/tests/unit/unit1397.c b/tests/unit/unit1397.c index 539433ca..432b9097 100644 --- a/tests/unit/unit1397.c +++ b/tests/unit/unit1397.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, 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 @@ -36,7 +36,7 @@ static void unit_stop(void) UNITTEST_START /* only these backends define the tested functions */ -#if defined(USE_OPENSSL) || defined(USE_AXTLS) || defined(USE_GSKIT) +#if defined(USE_OPENSSL) || defined(USE_GSKIT) /* here you start doing things and checking that the results are good */ diff --git a/tests/unit/unit1398.c b/tests/unit/unit1398.c index b7260195..22cc837e 100644 --- a/tests/unit/unit1398.c +++ b/tests/unit/unit1398.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, 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 @@ -74,7 +74,7 @@ fail_unless(!strcmp(output, " bu"), "wrong output"); /* output a number in a limited output */ rc = curl_msnprintf(output, 4, "%d", 10240); -/* TODO: this should return 5 to be POSIX/snprintf compliant! */ +/* TODO: this should return 5 to be POSIX/msnprintf compliant! */ fail_unless(rc == 4, "return code should be 4"); fail_unless(!strcmp(output, "102"), "wrong output"); diff --git a/tests/unit/unit1399.c b/tests/unit/unit1399.c index 897a3431..7383fbd8 100644 --- a/tests/unit/unit1399.c +++ b/tests/unit/unit1399.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2018, 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 @@ -63,7 +63,7 @@ static bool usec_matches_seconds(time_t time_usec, int expected_seconds) static void expect_timer_seconds(struct Curl_easy *data, int seconds) { char msg[64]; - snprintf(msg, sizeof(msg), "about %d seconds should have passed", seconds); + msnprintf(msg, sizeof(msg), "about %d seconds should have passed", seconds); fail_unless(usec_matches_seconds(data->progress.t_nslookup, seconds), msg); fail_unless(usec_matches_seconds(data->progress.t_connect, seconds), msg); fail_unless(usec_matches_seconds(data->progress.t_appconnect, seconds), msg); diff --git a/tests/unit/unit1604.c b/tests/unit/unit1604.c index fbfd2c42..c285ced4 100644 --- a/tests/unit/unit1604.c +++ b/tests/unit/unit1604.c @@ -46,11 +46,15 @@ static char *getflagstr(int flags) { char *buf = malloc(256); if(buf) { - snprintf(buf, 256, "%s,%s,%s,%s", - ((flags & SANITIZE_ALLOW_COLONS) ? "SANITIZE_ALLOW_COLONS" : ""), - ((flags & SANITIZE_ALLOW_PATH) ? "SANITIZE_ALLOW_PATH" : ""), - ((flags & SANITIZE_ALLOW_RESERVED) ? "SANITIZE_ALLOW_RESERVED" : ""), - ((flags & SANITIZE_ALLOW_TRUNCATE) ? "SANITIZE_ALLOW_TRUNCATE" : "")); + msnprintf(buf, 256, "%s,%s,%s,%s", + ((flags & SANITIZE_ALLOW_COLONS) ? + "SANITIZE_ALLOW_COLONS" : ""), + ((flags & SANITIZE_ALLOW_PATH) ? + "SANITIZE_ALLOW_PATH" : ""), + ((flags & SANITIZE_ALLOW_RESERVED) ? + "SANITIZE_ALLOW_RESERVED" : ""), + ((flags & SANITIZE_ALLOW_TRUNCATE) ? + "SANITIZE_ALLOW_TRUNCATE" : "")); } return buf; } @@ -59,13 +63,13 @@ static char *getcurlcodestr(int cc) { char *buf = malloc(256); if(buf) { - snprintf(buf, 256, "%s (%d)", - (cc == SANITIZE_ERR_OK ? "SANITIZE_ERR_OK" : - cc == SANITIZE_ERR_BAD_ARGUMENT ? "SANITIZE_ERR_BAD_ARGUMENT" : - cc == SANITIZE_ERR_INVALID_PATH ? "SANITIZE_ERR_INVALID_PATH" : - cc == SANITIZE_ERR_OUT_OF_MEMORY ? "SANITIZE_ERR_OUT_OF_MEMORY" : - "unexpected error code - add name"), - cc); + msnprintf(buf, 256, "%s (%d)", + (cc == SANITIZE_ERR_OK ? "SANITIZE_ERR_OK" : + cc == SANITIZE_ERR_BAD_ARGUMENT ? "SANITIZE_ERR_BAD_ARGUMENT" : + cc == SANITIZE_ERR_INVALID_PATH ? "SANITIZE_ERR_INVALID_PATH" : + cc == SANITIZE_ERR_OUT_OF_MEMORY ? "SANITIZE_ERR_OUT_OF_MEMORY": + "unexpected error code - add name"), + cc); } return buf; } diff --git a/tests/unit/unit1650.c b/tests/unit/unit1650.c index ddf228f8..4962bfac 100644 --- a/tests/unit/unit1650.c +++ b/tests/unit/unit1650.c @@ -200,7 +200,7 @@ UNITTEST_START a = &d.addr[u]; if(resp[i].type == DNS_TYPE_A) { p = &a->ip.v4[0]; - snprintf(ptr, len, "%u.%u.%u.%u ", p[0], p[1], p[2], p[3]); + msnprintf(ptr, len, "%u.%u.%u.%u ", p[0], p[1], p[2], p[3]); o = strlen(ptr); len -= o; ptr += o; @@ -209,20 +209,20 @@ UNITTEST_START int j; for(j = 0; j < 16; j += 2) { size_t l; - snprintf(ptr, len, "%s%02x%02x", j?":":"", a->ip.v6[j], + msnprintf(ptr, len, "%s%02x%02x", j?":":"", a->ip.v6[j], a->ip.v6[j + 1]); l = strlen(ptr); len -= l; ptr += l; } - snprintf(ptr, len, " "); + msnprintf(ptr, len, " "); len--; ptr++; } } for(u = 0; u < d.numcname; u++) { size_t o; - snprintf(ptr, len, "%s ", d.cname[u].alloc); + msnprintf(ptr, len, "%s ", d.cname[u].alloc); o = strlen(ptr); len -= o; ptr += o; @@ -271,8 +271,8 @@ UNITTEST_START fail_if(d.numaddr != 1, "missing address"); a = &d.addr[0]; p = &a->ip.v4[0]; - snprintf((char *)buffer, sizeof(buffer), - "%u.%u.%u.%u", p[0], p[1], p[2], p[3]); + msnprintf((char *)buffer, sizeof(buffer), + "%u.%u.%u.%u", p[0], p[1], p[2], p[3]); if(rc || strcmp((char *)buffer, "127.0.0.1")) { fprintf(stderr, "bad address decoded: %s, rc == %d\n", buffer, rc); return 7; diff --git a/tests/unit/unit1652.c b/tests/unit/unit1652.c new file mode 100644 index 00000000..9693fe63 --- /dev/null +++ b/tests/unit/unit1652.c @@ -0,0 +1,133 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2018, 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 "curlcheck.h" + +#include "urldata.h" +#include "sendf.h" + +/* + * This test hardcodes the knowledge of the buffer size which is internal to + * Curl_infof(). If that buffer is changed in size, this tests needs to be + * updated to still be valid. + */ + +static struct Curl_easy *data; + +static char input[4096]; +static char result[4096]; + +int debugf_cb(CURL *handle, curl_infotype type, char *buf, size_t size, + void *userptr); + +/* + * This debugf callback is simply dumping the string into the static buffer + * for the unit test to inspect. Since we know that we're only dealing with + * text we can afford the luxury of skipping the type check here. + */ +int +debugf_cb(CURL *handle, curl_infotype type, char *buf, size_t size, + void *userptr) +{ + (void)handle; + (void)type; + (void)userptr; + + memset(result, '\0', sizeof(result)); + memcpy(result, buf, size); + return 0; +} + +static CURLcode +unit_setup(void) +{ + int res = 0; + + global_init(CURL_GLOBAL_ALL); + data = curl_easy_init(); + if(!data) + return CURLE_OUT_OF_MEMORY; + curl_easy_setopt(data, CURLOPT_DEBUGFUNCTION, debugf_cb); + curl_easy_setopt(data, CURLOPT_VERBOSE, 1L); + return CURLE_OK; +} + +static void +unit_stop(void) +{ + curl_easy_cleanup(data); + curl_global_cleanup(); +} + +UNITTEST_START + +/* Injecting a simple short string via a format */ +msnprintf(input, sizeof(input), "Simple Test"); +Curl_infof(data, "%s", input); +fail_unless(strcmp(result, input) == 0, "Simple string test"); + +/* Injecting a few different variables with a format */ +Curl_infof(data, "%s %u testing %lu\n", input, 42, 43L); +fail_unless(strcmp(result, "Simple Test 42 testing 43\n") == 0, + "Format string"); + +/* Variations of empty strings */ +Curl_infof(data, ""); +fail_unless(strlen(result) == 0, "Empty string"); +Curl_infof(data, "%s", NULL); +fail_unless(strcmp(result, "(nil)") == 0, "Passing NULL as string"); + +/* A string just long enough to not be truncated */ +memset(input, '\0', sizeof(input)); +memset(input, 'A', 2048); +Curl_infof(data, "%s", input); +fail_unless(strlen(result) == 2048, "No truncation of infof input"); +fail_unless(strcmp(result, input) == 0, "No truncation of infof input"); +fail_unless(result[sizeof(result) - 1] == '\0', + "No truncation of infof input"); + +/* Just over the limit for truncation without newline */ +memset(input + 2047, 'A', 4); +Curl_infof(data, "%s", input); +fail_unless(strlen(result) == 2048, "Truncation of infof input 1"); +fail_unless(result[sizeof(result) - 1] == '\0', "Truncation of infof input 1"); +fail_unless(strncmp(result + 2045, "...", 3) == 0, + "Truncation of infof input 1"); + +/* Just over the limit for truncation with newline */ +memset(input + 2047, 'A', 4); +memset(input + 2047 + 4, '\n', 1); +Curl_infof(data, "%s\n", input); +fail_unless(strlen(result) == 2048, "Truncation of infof input 2"); +fail_unless(result[sizeof(result) - 1] == '\0', "Truncation of infof input 2"); +fail_unless(strncmp(result + 2044, "...", 3) == 0, + "Truncation of infof input 2"); + +/* Way over the limit for truncation with newline */ +memset(input, '\0', sizeof(input)); +memset(input, 'A', sizeof(input) - 1); +Curl_infof(data, "%s\n", input); +fail_unless(strlen(result) == 2048, "Truncation of infof input 3"); +fail_unless(result[sizeof(result) - 1] == '\0', "Truncation of infof input 3"); +fail_unless(strncmp(result + 2044, "...", 3) == 0, + "Truncation of infof input 3"); + +UNITTEST_STOP diff --git a/tests/unit/unit1653.c b/tests/unit/unit1653.c new file mode 100644 index 00000000..9851ee58 --- /dev/null +++ b/tests/unit/unit1653.c @@ -0,0 +1,129 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2018, 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 "curlcheck.h" + +#include "urldata.h" +#include "curl/urlapi.h" +#include "urlapi-int.h" + + +static CURLU *u; + +static CURLcode +unit_setup(void) +{ + return CURLE_OK; +} + +static void +unit_stop(void) +{ + curl_global_cleanup(); +} + +UNITTEST_START + + CURLUcode ret; + char *ipv6port; + char *portnum; + + /* Valid IPv6 */ + u = curl_url(); + ipv6port = strdup("[fe80::250:56ff:fea7:da15]"); + ret = Curl_parse_port(u, ipv6port); + fail_unless(ret == CURLUE_OK, "Curl_parse_port returned error"); + ret = curl_url_get(u, CURLUPART_PORT, &portnum, CURLU_NO_DEFAULT_PORT); + fail_unless(ret != CURLUE_OK, "curl_url_get portnum returned something"); + free(ipv6port); + curl_url_cleanup(u); + + /* Invalid IPv6 */ + u = curl_url(); + ipv6port = strdup("[fe80::250:56ff:fea7:da15|"); + ret = Curl_parse_port(u, ipv6port); + fail_unless(ret != CURLUE_OK, "Curl_parse_port true on error"); + free(ipv6port); + curl_url_cleanup(u); + + u = curl_url(); + ipv6port = strdup("[fe80::250:56ff;fea7:da15]:80"); + ret = Curl_parse_port(u, ipv6port); + fail_unless(ret != CURLUE_OK, "Curl_parse_port true on error"); + free(ipv6port); + curl_url_cleanup(u); + + /* Valid IPv6 with zone index and port number */ + u = curl_url(); + ipv6port = strdup("[fe80::250:56ff:fea7:da15%25eth3]:80"); + ret = Curl_parse_port(u, ipv6port); + fail_unless(ret == CURLUE_OK, "Curl_parse_port returned error"); + ret = curl_url_get(u, CURLUPART_PORT, &portnum, 0); + fail_unless(ret == CURLUE_OK, "curl_url_get portnum returned error"); + fail_unless(strcmp(portnum, "80") == 0, "Check portnumber"); + curl_free(portnum); + free(ipv6port); + curl_url_cleanup(u); + + /* Valid IPv6 with port number */ + u = curl_url(); + ipv6port = strdup("[fe80::250:56ff:fea7:da15]:81"); + ret = Curl_parse_port(u, ipv6port); + fail_unless(ret == CURLUE_OK, "Curl_parse_port returned error"); + ret = curl_url_get(u, CURLUPART_PORT, &portnum, 0); + fail_unless(ret == CURLUE_OK, "curl_url_get portnum returned error"); + fail_unless(strcmp(portnum, "81") == 0, "Check portnumber"); + curl_free(portnum); + free(ipv6port); + curl_url_cleanup(u); + + /* Valid IPv6 with syntax error in the port number */ + u = curl_url(); + ipv6port = strdup("[fe80::250:56ff:fea7:da15];81"); + ret = Curl_parse_port(u, ipv6port); + fail_unless(ret != CURLUE_OK, "Curl_parse_port true on error"); + free(ipv6port); + curl_url_cleanup(u); + + u = curl_url(); + ipv6port = strdup("[fe80::250:56ff:fea7:da15]80"); + ret = Curl_parse_port(u, ipv6port); + fail_unless(ret != CURLUE_OK, "Curl_parse_port true on error"); + free(ipv6port); + curl_url_cleanup(u); + + /* Incorrect zone index syntax */ + u = curl_url(); + ipv6port = strdup("[fe80::250:56ff:fea7:da15%!25eth3]:80"); + ret = Curl_parse_port(u, ipv6port); + fail_unless(ret != CURLUE_OK, "Curl_parse_port returned non-error"); + free(ipv6port); + curl_url_cleanup(u); + + /* Non percent-encoded zone index */ + u = curl_url(); + ipv6port = strdup("[fe80::250:56ff:fea7:da15%eth3]:80"); + ret = Curl_parse_port(u, ipv6port); + fail_unless(ret != CURLUE_OK, "Curl_parse_port returned non-error"); + free(ipv6port); + curl_url_cleanup(u); + +UNITTEST_STOP |