aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/libtest/lib1502.c5
-rw-r--r--tests/libtest/lib1506.c7
-rw-r--r--tests/libtest/lib1510.c7
-rw-r--r--tests/libtest/lib1512.c9
-rw-r--r--tests/libtest/lib1900.c4
-rw-r--r--tests/libtest/lib518.c70
-rw-r--r--tests/libtest/lib530.c4
-rw-r--r--tests/libtest/lib537.c123
-rw-r--r--tests/libtest/lib540.c4
-rw-r--r--tests/libtest/lib553.c4
-rw-r--r--tests/libtest/libauthretry.c7
-rw-r--r--tests/libtest/libntlmconnect.c27
-rw-r--r--tests/libtest/test.h6
13 files changed, 143 insertions, 134 deletions
diff --git a/tests/libtest/lib1502.c b/tests/libtest/lib1502.c
index 2336a8d3a..e4e1a162a 100644
--- a/tests/libtest/lib1502.c
+++ b/tests/libtest/lib1502.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2016, 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
@@ -51,7 +51,8 @@ int test(char *URL)
/* DNS cache injection */
struct curl_slist *dns_cache_list;
- sprintf(redirect, "google.com:%s:%s", libtest_arg2, libtest_arg3);
+ snprintf(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 0551f04b7..9e03e63f0 100644
--- a/tests/libtest/lib1506.c
+++ b/tests/libtest/lib1506.c
@@ -46,7 +46,7 @@ int test(char *URL)
/* Create fake DNS entries for serverX.example.com for all handles */
for(i=0; i < NUM_HANDLES; i++) {
- sprintf(dnsentry, "server%d.example.com:%s:%s", i + 1, port, address);
+ snprintf(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) {
@@ -69,8 +69,9 @@ int test(char *URL)
/* get an easy handle */
easy_init(curl[i]);
/* specify target */
- sprintf(target_url, "http://server%d.example.com:%s/path/1506%04i",
- i + 1, port, i + 1);
+ snprintf(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 3d791e01e..d28bef39a 100644
--- a/tests/libtest/lib1510.c
+++ b/tests/libtest/lib1510.c
@@ -44,7 +44,7 @@ int test(char *URL)
/* Create fake DNS entries for serverX.example.com for all handles */
for(i=0; i < NUM_URLS; i++) {
- sprintf(dnsentry, "server%d.example.com:%s:%s", i + 1, port, address);
+ snprintf(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) {
@@ -73,8 +73,9 @@ int test(char *URL)
/* get NUM_HANDLES easy handles */
for(i=0; i < NUM_URLS; i++) {
/* specify target */
- sprintf(target_url, "http://server%d.example.com:%s/path/1510%04i",
- i + 1, port, i + 1);
+ snprintf(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 759898737..bf03e1a4f 100644
--- a/tests/libtest/lib1512.c
+++ b/tests/libtest/lib1512.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 2013, Linus Nielsen Feltzing <linus@haxx.se>
+ * Copyright (C) 2013 - 2016, 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,7 +49,7 @@ int test(char *URL)
return TEST_ERR_MAJOR_BAD;
}
- sprintf(dnsentry, "server.example.curl:%s:%s", port, address);
+ snprintf(dnsentry, sizeof(dnsentry), "server.example.curl:%s:%s", port, address);
printf("%s\n", dnsentry);
slist = curl_slist_append(slist, dnsentry);
@@ -58,8 +58,9 @@ int test(char *URL)
/* get an easy handle */
easy_init(curl[i]);
/* specify target */
- sprintf(target_url, "http://server.example.curl:%s/path/1512%04i",
- port, i + 1);
+ snprintf(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/lib1900.c b/tests/libtest/lib1900.c
index f52a9c2d1..0c6328483 100644
--- a/tests/libtest/lib1900.c
+++ b/tests/libtest/lib1900.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 2013, Linus Nielsen Feltzing, <linus@haxx.se>
+ * Copyright (C) 2013 - 2016, 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];
- sprintf(urlbuf, "%s%s", base_url, urlstring[handlenum]);
+ snprintf(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 94343f67c..3e6c492dc 100644
--- a/tests/libtest/lib518.c
+++ b/tests/libtest/lib518.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2016, 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
@@ -57,9 +57,9 @@ static char msgbuff[256];
static void store_errmsg(const char *msg, int err)
{
if (!err)
- sprintf(msgbuff, "%s", msg);
+ snprintf(msgbuff, sizeof(msgbuff), "%s", msg);
else
- sprintf(msgbuff, "%s, errno %d, %s", msg, err, strerror(err));
+ snprintf(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
- sprintf(strbuff, fmt, rl.rlim_cur);
+ snprintf(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
- sprintf(strbuff, fmt, rl.rlim_max);
+ snprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_max);
fprintf(stderr, "initial hard limit: %s\n", strbuff);
/* show our constants */
@@ -199,7 +199,7 @@ static int rlimit(int keep_open)
strcpy(strbuff, "INFINITY");
else
#endif
- sprintf(strbuff, fmt, rl.rlim_cur);
+ snprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_cur);
fprintf(stderr, "current soft limit: %s\n", strbuff);
#ifdef RLIM_INFINITY
@@ -207,7 +207,7 @@ static int rlimit(int keep_open)
strcpy(strbuff, "INFINITY");
else
#endif
- sprintf(strbuff, fmt, rl.rlim_max);
+ snprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_max);
fprintf(stderr, "current hard limit: %s\n", strbuff);
} /* (rl.rlim_cur != rl.rlim_max) */
@@ -234,10 +234,10 @@ static int rlimit(int keep_open)
(rl.rlim_cur != RLIM_INFINITY) &&
#endif
(rl.rlim_cur <= num_open.rlim_cur)) {
- sprintf(strbuff2, fmt, rl.rlim_cur);
- sprintf(strbuff1, fmt, num_open.rlim_cur);
- sprintf(strbuff, "fds needed %s > system limit %s",
- strbuff1, strbuff2);
+ 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);
store_errmsg(strbuff, 0);
fprintf(stderr, "%s\n", msgbuff);
return -4;
@@ -258,7 +258,7 @@ static int rlimit(int keep_open)
nitems = 0x40000;
do {
num_open.rlim_max = sizeof(*memchunk) * (size_t)nitems;
- sprintf(strbuff, fmt, num_open.rlim_max);
+ snprintf(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) {
@@ -286,9 +286,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)) {
- sprintf(strbuff1, fmt, num_open.rlim_max);
- sprintf(strbuff, "unable to allocate an array for %s "
- "file descriptors, would overflow size_t", strbuff1);
+ 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);
store_errmsg(strbuff, 0);
fprintf(stderr, "%s\n", msgbuff);
free(memchunk);
@@ -297,7 +297,7 @@ static int rlimit(int keep_open)
/* allocate array for file descriptors */
- sprintf(strbuff, fmt, num_open.rlim_max);
+ snprintf(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));
@@ -317,14 +317,14 @@ static int rlimit(int keep_open)
num_open.rlim_cur++)
fd[num_open.rlim_cur] = -1;
- sprintf(strbuff, fmt, num_open.rlim_max);
+ snprintf(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) {
- sprintf(strbuff, "opening of %s failed", DEV_NULL);
+ snprintf(strbuff, sizeof(strbuff), "opening of %s failed", DEV_NULL);
store_errmsg(strbuff, ERRNO);
fprintf(stderr, "%s\n", msgbuff);
free(fd);
@@ -345,20 +345,20 @@ static int rlimit(int keep_open)
fd[num_open.rlim_cur] = -1;
- sprintf(strbuff1, fmt, num_open.rlim_cur);
- sprintf(strbuff, "dup() attempt %s failed", strbuff1);
+ snprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_cur);
+ snprintf(strbuff, sizeof(strbuff), "dup() attempt %s failed", strbuff1);
fprintf(stderr, "%s\n", strbuff);
- sprintf(strbuff1, fmt, num_open.rlim_cur);
- sprintf(strbuff, "fds system limit seems close to %s", strbuff1);
+ snprintf(strbuff1, sizeof(strbuff), fmt, num_open.rlim_cur);
+ snprintf(strbuff, sizeof(strbuff), "fds system limit seems close to %s", strbuff1);
fprintf(stderr, "%s\n", strbuff);
num_open.rlim_max = NUM_NEEDED;
- sprintf(strbuff2, fmt, num_open.rlim_max);
- sprintf(strbuff1, fmt, num_open.rlim_cur);
- sprintf(strbuff, "fds needed %s > system limit %s",
- strbuff2, strbuff1);
+ 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",
+ strbuff2, strbuff1);
store_errmsg(strbuff, 0);
fprintf(stderr, "%s\n", msgbuff);
@@ -375,7 +375,7 @@ static int rlimit(int keep_open)
}
- sprintf(strbuff, fmt, num_open.rlim_max);
+ snprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max);
fprintf(stderr, "%s file descriptors open\n", strbuff);
#if !defined(HAVE_POLL_FINE) && \
@@ -395,7 +395,8 @@ static int rlimit(int keep_open)
num_open.rlim_cur = FD_SETSIZE - SAFETY_MARGIN;
if (num_open.rlim_max > num_open.rlim_cur) {
- sprintf(strbuff, "select limit is FD_SETSIZE %d", FD_SETSIZE);
+ snprintf(strbuff, sizeof(strbuff), "select limit is FD_SETSIZE %d",
+ FD_SETSIZE);
store_errmsg(strbuff, 0);
fprintf(stderr, "%s\n", msgbuff);
close_file_descriptors();
@@ -409,7 +410,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)) {
- sprintf(strbuff, "select limit is FD_SETSIZE %d", FD_SETSIZE);
+ snprintf(strbuff, sizeof(strbuff), "select limit is FD_SETSIZE %d",
+ FD_SETSIZE);
store_errmsg(strbuff, 0);
fprintf(stderr, "%s\n", msgbuff);
close_file_descriptors();
@@ -430,11 +432,13 @@ static int rlimit(int keep_open)
*/
if (!fopen_works()) {
- sprintf(strbuff1, fmt, num_open.rlim_max);
- sprintf(strbuff, "stdio fopen() fails with %s fds open()",
- strbuff1);
+ snprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_max);
+ snprintf(strbuff, sizeof(strbuff),
+ "stdio fopen() fails with %s fds open()",
+ strbuff1);
fprintf(stderr, "%s\n", msgbuff);
- sprintf(strbuff, "stdio fopen() fails with lots of fds open()");
+ snprintf(strbuff, sizeof(strbuff),
+ "stdio fopen() fails with lots of fds open()");
store_errmsg(strbuff, 0);
close_file_descriptors();
free(memchunk);
diff --git a/tests/libtest/lib530.c b/tests/libtest/lib530.c
index a3e2d0cb5..82bfab36c 100644
--- a/tests/libtest/lib530.c
+++ b/tests/libtest/lib530.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2016, 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 */
- sprintf(target_url, "%s%04i", URL, i + 1);
+ snprintf(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 88cbceaec..3e00776a3 100644
--- a/tests/libtest/lib537.c
+++ b/tests/libtest/lib537.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2013, 2016, 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
@@ -57,10 +57,11 @@ static char msgbuff[256];
static void store_errmsg(const char *msg, int err)
{
- if (!err)
- sprintf(msgbuff, "%s", msg);
+ if(!err)
+ snprintf(msgbuff, sizeof(msgbuff), "%s", msg);
else
- sprintf(msgbuff, "%s, errno %d, %s", msg, err, strerror(err));
+ snprintf(msgbuff, sizeof(msgbuff), "%s, errno %d, %s", msg, err,
+ strerror(err));
}
static void close_file_descriptors(void)
@@ -68,7 +69,7 @@ static void close_file_descriptors(void)
for (num_open.rlim_cur = 0;
num_open.rlim_cur < num_open.rlim_max;
num_open.rlim_cur++)
- if (fd[num_open.rlim_cur] > 0)
+ if(fd[num_open.rlim_cur] > 0)
close(fd[num_open.rlim_cur]);
free(fd);
fd = NULL;
@@ -85,7 +86,7 @@ static int fopen_works(void)
}
for (i = 0; i < 3; i++) {
fpa[i] = fopen(DEV_NULL, "r");
- if (fpa[i] == NULL) {
+ if(fpa[i] == NULL) {
store_errmsg("fopen() failed", ERRNO);
fprintf(stderr, "%s\n", msgbuff);
ret = 0;
@@ -93,7 +94,7 @@ static int fopen_works(void)
}
}
for (i = 0; i < 3; i++) {
- if (fpa[i] != NULL)
+ if(fpa[i] != NULL)
fclose(fpa[i]);
}
return ret;
@@ -113,7 +114,7 @@ static int rlimit(int keep_open)
#ifdef HAVE_LONGLONG
char fmt_llu[] = "%llu";
- if (sizeof(rl.rlim_max) > sizeof(long))
+ if(sizeof(rl.rlim_max) > sizeof(long))
fmt = fmt_llu;
else
#endif
@@ -121,7 +122,7 @@ static int rlimit(int keep_open)
/* get initial open file limits */
- if (getrlimit(RLIMIT_NOFILE, &rl) != 0) {
+ if(getrlimit(RLIMIT_NOFILE, &rl) != 0) {
store_errmsg("getrlimit() failed", ERRNO);
fprintf(stderr, "%s\n", msgbuff);
return -1;
@@ -130,19 +131,19 @@ static int rlimit(int keep_open)
/* show initial open file limits */
#ifdef RLIM_INFINITY
- if (rl.rlim_cur == RLIM_INFINITY)
+ if(rl.rlim_cur == RLIM_INFINITY)
strcpy(strbuff, "INFINITY");
else
#endif
- sprintf(strbuff, fmt, rl.rlim_cur);
+ snprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_cur);
fprintf(stderr, "initial soft limit: %s\n", strbuff);
#ifdef RLIM_INFINITY
- if (rl.rlim_max == RLIM_INFINITY)
+ if(rl.rlim_max == RLIM_INFINITY)
strcpy(strbuff, "INFINITY");
else
#endif
- sprintf(strbuff, fmt, rl.rlim_max);
+ snprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_max);
fprintf(stderr, "initial hard limit: %s\n", strbuff);
/*
@@ -154,14 +155,14 @@ static int rlimit(int keep_open)
* open more than soft limit file descriptors will fail.
*/
- if (rl.rlim_cur != rl.rlim_max) {
+ if(rl.rlim_cur != rl.rlim_max) {
#ifdef OPEN_MAX
- if ((rl.rlim_cur > 0) &&
+ if((rl.rlim_cur > 0) &&
(rl.rlim_cur < OPEN_MAX)) {
fprintf(stderr, "raising soft limit up to OPEN_MAX\n");
rl.rlim_cur = OPEN_MAX;
- if (setrlimit(RLIMIT_NOFILE, &rl) != 0) {
+ if(setrlimit(RLIMIT_NOFILE, &rl) != 0) {
/* on failure don't abort just issue a warning */
store_errmsg("setrlimit() failed", ERRNO);
fprintf(stderr, "%s\n", msgbuff);
@@ -172,7 +173,7 @@ static int rlimit(int keep_open)
fprintf(stderr, "raising soft limit up to hard limit\n");
rl.rlim_cur = rl.rlim_max;
- if (setrlimit(RLIMIT_NOFILE, &rl) != 0) {
+ if(setrlimit(RLIMIT_NOFILE, &rl) != 0) {
/* on failure don't abort just issue a warning */
store_errmsg("setrlimit() failed", ERRNO);
fprintf(stderr, "%s\n", msgbuff);
@@ -181,7 +182,7 @@ static int rlimit(int keep_open)
/* get current open file limits */
- if (getrlimit(RLIMIT_NOFILE, &rl) != 0) {
+ if(getrlimit(RLIMIT_NOFILE, &rl) != 0) {
store_errmsg("getrlimit() failed", ERRNO);
fprintf(stderr, "%s\n", msgbuff);
return -3;
@@ -190,19 +191,19 @@ static int rlimit(int keep_open)
/* show current open file limits */
#ifdef RLIM_INFINITY
- if (rl.rlim_cur == RLIM_INFINITY)
+ if(rl.rlim_cur == RLIM_INFINITY)
strcpy(strbuff, "INFINITY");
else
#endif
- sprintf(strbuff, fmt, rl.rlim_cur);
+ snprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_cur);
fprintf(stderr, "current soft limit: %s\n", strbuff);
#ifdef RLIM_INFINITY
- if (rl.rlim_max == RLIM_INFINITY)
+ if(rl.rlim_max == RLIM_INFINITY)
strcpy(strbuff, "INFINITY");
else
#endif
- sprintf(strbuff, fmt, rl.rlim_max);
+ snprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_max);
fprintf(stderr, "current hard limit: %s\n", strbuff);
} /* (rl.rlim_cur != rl.rlim_max) */
@@ -228,19 +229,19 @@ static int rlimit(int keep_open)
for (nitems = i = 1; nitems <= i; i *= 2)
nitems = i;
- if (nitems > 0x7fff)
+ if(nitems > 0x7fff)
nitems = 0x40000;
do {
num_open.rlim_max = sizeof(*memchunk) * (size_t)nitems;
- sprintf(strbuff, fmt, num_open.rlim_max);
+ snprintf(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) {
+ if(!memchunk) {
fprintf(stderr, "memchunk, malloc() failed\n");
nitems /= 2;
}
} while (nitems && !memchunk);
- if (!memchunk) {
+ if(!memchunk) {
store_errmsg("memchunk, malloc() failed", ERRNO);
fprintf(stderr, "%s\n", msgbuff);
return -4;
@@ -256,9 +257,9 @@ static int rlimit(int keep_open)
/* set the number of file descriptors we will try to open */
#ifdef RLIM_INFINITY
- if ((rl.rlim_cur > 0) && (rl.rlim_cur != RLIM_INFINITY)) {
+ if((rl.rlim_cur > 0) && (rl.rlim_cur != RLIM_INFINITY)) {
#else
- if (rl.rlim_cur > 0) {
+ if(rl.rlim_cur > 0) {
#endif
/* soft limit minus SAFETY_MARGIN */
num_open.rlim_max = rl.rlim_cur - SAFETY_MARGIN;
@@ -267,17 +268,17 @@ static int rlimit(int keep_open)
/* a huge number of file descriptors */
for (nitems = i = 1; nitems <= i; i *= 2)
nitems = i;
- if (nitems > 0x7fff)
+ if(nitems > 0x7fff)
nitems = 0x40000;
num_open.rlim_max = nitems;
}
/* verify that we won't overflow size_t in malloc() */
- if ((size_t)(num_open.rlim_max) > ((size_t)-1) / sizeof(*fd)) {
- sprintf(strbuff1, fmt, num_open.rlim_max);
- sprintf(strbuff, "unable to allocate an array for %s "
- "file descriptors, would overflow size_t", strbuff1);
+ 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);
store_errmsg(strbuff, 0);
fprintf(stderr, "%s\n", msgbuff);
free(memchunk);
@@ -287,15 +288,15 @@ static int rlimit(int keep_open)
/* allocate array for file descriptors */
do {
- sprintf(strbuff, fmt, num_open.rlim_max);
+ snprintf(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) {
+ if(!fd) {
fprintf(stderr, "fd, malloc() failed\n");
num_open.rlim_max /= 2;
}
} while (num_open.rlim_max && !fd);
- if (!fd) {
+ if(!fd) {
store_errmsg("fd, malloc() failed", ERRNO);
fprintf(stderr, "%s\n", msgbuff);
free(memchunk);
@@ -311,14 +312,14 @@ static int rlimit(int keep_open)
num_open.rlim_cur++)
fd[num_open.rlim_cur] = -1;
- sprintf(strbuff, fmt, num_open.rlim_max);
+ snprintf(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) {
- sprintf(strbuff, "opening of %s failed", DEV_NULL);
+ if(fd[0] < 0) {
+ snprintf(strbuff, sizeof(strbuff), "opening of %s failed", DEV_NULL);
store_errmsg(strbuff, ERRNO);
fprintf(stderr, "%s\n", msgbuff);
free(fd);
@@ -335,23 +336,23 @@ static int rlimit(int keep_open)
fd[num_open.rlim_cur] = dup(fd[0]);
- if (fd[num_open.rlim_cur] < 0) {
+ if(fd[num_open.rlim_cur] < 0) {
fd[num_open.rlim_cur] = -1;
- sprintf(strbuff1, fmt, num_open.rlim_cur);
- sprintf(strbuff, "dup() attempt %s failed", strbuff1);
+ snprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_cur);
+ snprintf(strbuff, sizeof(strbuff), "dup() attempt %s failed", strbuff1);
fprintf(stderr, "%s\n", strbuff);
- sprintf(strbuff1, fmt, num_open.rlim_cur);
- sprintf(strbuff, "fds system limit seems close to %s", strbuff1);
+ snprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_cur);
+ snprintf(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;
- sprintf(strbuff1, fmt, num_open.rlim_cur);
- sprintf(strbuff, "closing %s file descriptors", strbuff1);
+ snprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_cur);
+ snprintf(strbuff, sizeof(strbuff), "closing %s file descriptors", strbuff1);
fprintf(stderr, "%s\n", strbuff);
for (num_open.rlim_cur = num_open.rlim_max;
@@ -361,13 +362,13 @@ static int rlimit(int keep_open)
fd[num_open.rlim_cur] = -1;
}
- sprintf(strbuff, fmt, num_open.rlim_max);
+ snprintf(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 */
tmpfd = realloc(fd, sizeof(*fd) * (size_t)(num_open.rlim_max));
- if (tmpfd) {
+ if(tmpfd) {
fd = tmpfd;
tmpfd = NULL;
}
@@ -378,7 +379,7 @@ static int rlimit(int keep_open)
}
- sprintf(strbuff, fmt, num_open.rlim_max);
+ snprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max);
fprintf(stderr, "%s file descriptors open\n", strbuff);
#if !defined(HAVE_POLL_FINE) && \
@@ -397,8 +398,8 @@ static int rlimit(int keep_open)
*/
num_open.rlim_cur = FD_SETSIZE - SAFETY_MARGIN;
- if (num_open.rlim_max > num_open.rlim_cur) {
- sprintf(strbuff, "select limit is FD_SETSIZE %d", FD_SETSIZE);
+ if(num_open.rlim_max > num_open.rlim_cur) {
+ snprintf(strbuff, sizeof(strbuff), "select limit is FD_SETSIZE %d", FD_SETSIZE);
store_errmsg(strbuff, 0);
fprintf(stderr, "%s\n", msgbuff);
close_file_descriptors();
@@ -410,9 +411,9 @@ static int rlimit(int keep_open)
for (rl.rlim_cur = 0;
rl.rlim_cur < num_open.rlim_max;
rl.rlim_cur++) {
- if ((fd[rl.rlim_cur] > 0) &&
+ if((fd[rl.rlim_cur] > 0) &&
((unsigned int)fd[rl.rlim_cur] > num_open.rlim_cur)) {
- sprintf(strbuff, "select limit is FD_SETSIZE %d", FD_SETSIZE);
+ snprintf(strbuff, sizeof(strbuff), "select limit is FD_SETSIZE %d", FD_SETSIZE);
store_errmsg(strbuff, 0);
fprintf(stderr, "%s\n", msgbuff);
close_file_descriptors();
@@ -432,12 +433,12 @@ static int rlimit(int keep_open)
* if it is capable of fopen()ing some additional files.
*/
- if (!fopen_works()) {
- sprintf(strbuff1, fmt, num_open.rlim_max);
- sprintf(strbuff, "stdio fopen() fails with %s fds open()",
+ if(!fopen_works()) {
+ snprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_max);
+ snprintf(strbuff, sizeof(strbuff), "stdio fopen() fails with %s fds open()",
strbuff1);
fprintf(stderr, "%s\n", msgbuff);
- sprintf(strbuff, "stdio fopen() fails with lots of fds open()");
+ snprintf(strbuff, sizeof(strbuff), "stdio fopen() fails with lots of fds open()");
store_errmsg(strbuff, 0);
close_file_descriptors();
free(memchunk);
@@ -451,7 +452,7 @@ static int rlimit(int keep_open)
/* close file descriptors unless instructed to keep them */
- if (!keep_open) {
+ if(!keep_open) {
close_file_descriptors();
}
@@ -472,7 +473,7 @@ int test(char *URL)
return 0; /* sure, run this! */
}
- if (rlimit(TRUE)) {
+ if(rlimit(TRUE)) {
/* failure */
return TEST_ERR_MAJOR_BAD;
}
@@ -480,13 +481,13 @@ int test(char *URL)
/* run the test with the bunch of open file descriptors
and close them all once the test is over */
- if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
+ if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
fprintf(stderr, "curl_global_init() failed\n");
close_file_descriptors();
return TEST_ERR_MAJOR_BAD;
}
- if ((curl = curl_easy_init()) == NULL) {
+ if((curl = curl_easy_init()) == NULL) {
fprintf(stderr, "curl_easy_init() failed\n");
close_file_descriptors();
curl_global_cleanup();
diff --git a/tests/libtest/lib540.c b/tests/libtest/lib540.c
index 62d8dfd1d..89dc6bc77 100644
--- a/tests/libtest/lib540.c
+++ b/tests/libtest/lib540.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2016, 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
@@ -200,7 +200,7 @@ int test(char *URL)
if(test_argc < 4)
return 99;
- sprintf(buffer, "Host: %s", HOST);
+ snprintf(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 96d569901..ab4db74c7 100644
--- a/tests/libtest/lib553.c
+++ b/tests/libtest/lib553.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2016, 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 @@ int test(char *URL)
}
for (i = 0; i < NUM_HEADERS; i++) {
- int len = sprintf(buf, "Header%d: ", i);
+ int len = snprintf(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/libauthretry.c b/tests/libtest/libauthretry.c
index eabe5bfbe..fac07fbee 100644
--- a/tests/libtest/libauthretry.c
+++ b/tests/libtest/libauthretry.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2016, 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
@@ -32,13 +32,14 @@ static CURLcode send_request(CURL *curl, const char *url, int seq,
long auth_scheme, const char *userpwd)
{
CURLcode res;
- char* full_url = malloc(strlen(url) + 4 + 1);
+ size_t len = strlen(url) + 4 + 1;
+ char* full_url = malloc(len);
if (!full_url) {
fprintf(stderr, "Not enough memory for full url\n");
return CURLE_OUT_OF_MEMORY;
}
- sprintf(full_url, "%s%04d", url, seq);
+ snprintf(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 a9609673d..0e2e9f4a6 100644
--- a/tests/libtest/libntlmconnect.c
+++ b/tests/libtest/libntlmconnect.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 2012 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 2012 - 2016, 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
@@ -103,11 +103,12 @@ int test(char *url)
int i, j;
int num_handles = 0;
enum HandleState state = ReadyForNewHandle;
- char* full_url = malloc(strlen(url) + 4 + 1);
+ size_t urllen = strlen(url) + 4 + 1;
+ char* full_url = malloc(urllen);
start_test_timing();
- if (!full_url) {
+ if(!full_url) {
fprintf(stderr, "Not enough memory for full url\n");
return TEST_ERR_MAJOR_BAD;
}
@@ -141,14 +142,14 @@ int test(char *url)
bool found_new_socket = FALSE;
/* Start a new handle if we aren't at the max */
- if (state == ReadyForNewHandle) {
+ if(state == ReadyForNewHandle) {
easy_init(easy[num_handles]);
- if (num_handles % 3 == 2) {
- sprintf(full_url, "%s0200", url);
+ if(num_handles % 3 == 2) {
+ snprintf(full_url, urllen, "%s0200", url);
easy_setopt(easy[num_handles], CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
} else {
- sprintf(full_url, "%s0100", url);
+ snprintf(full_url, urllen, "%s0100", url);
easy_setopt(easy[num_handles], CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
}
easy_setopt(easy[num_handles], CURLOPT_FRESH_CONNECT, 1L);
@@ -185,30 +186,30 @@ int test(char *url)
bool socket_exists = FALSE;
curl_socket_t curfd = (curl_socket_t)i;
- if (!FD_ISSET(curfd, &fdread)) {
+ if(!FD_ISSET(curfd, &fdread)) {
continue;
}
/* Check if this socket was already detected for an earlier handle (or
for this handle, num_handles-1, in the callback */
for (j = 0; j < num_handles; ++j) {
- if (sockets[j] == curfd) {
+ if(sockets[j] == curfd) {
socket_exists = TRUE;
break;
}
}
- if (socket_exists) {
+ if(socket_exists) {
continue;
}
- if (found_new_socket || state != NeedSocketForNewHandle) {
+ if(found_new_socket || state != NeedSocketForNewHandle) {
fprintf(stderr, "Unexpected new socket\n");
res = TEST_ERR_MAJOR_BAD;
goto test_cleanup;
}
/* Now we know the socket is for the most recent handle, num_handles-1 */
- if (sockets[num_handles-1] != CURL_SOCKET_BAD) {
+ if(sockets[num_handles-1] != CURL_SOCKET_BAD) {
/* A socket for this handle was already detected in the callback; if it
matched socket_exists should be true and we would never get here */
assert(curfd != sockets[num_handles-1]);
@@ -224,7 +225,7 @@ int test(char *url)
}
}
- if (state == NeedSocketForNewHandle) {
+ if(state == NeedSocketForNewHandle) {
if(maxfd != -1 && !found_new_socket) {
fprintf(stderr, "Warning: socket did not open immediately for new "
"handle (trying again)\n");
diff --git a/tests/libtest/test.h b/tests/libtest/test.h
index f724e4279..4bf6dcfe2 100644
--- a/tests/libtest/test.h
+++ b/tests/libtest/test.h
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2016, 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
@@ -40,9 +40,7 @@
# include "select.h"
#endif
-#define _MPRINTF_REPLACE
-#include <curl/mprintf.h>
-
+#include "curl_printf.h"
#define test_setopt(A,B,C) \
if((res = curl_easy_setopt((A),(B),(C))) != CURLE_OK) goto test_cleanup