Imported Upstream version 7.50.2
[platform/upstream/curl.git] / tests / libtest / lib1506.c
index 008a9ca..47fc335 100644 (file)
@@ -9,7 +9,7 @@
  *
  * 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 http://curl.haxx.se/docs/copyright.html.
+ * 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
 int test(char *URL)
 {
   int res = 0;
-  CURL *curl[NUM_HANDLES];
+  CURL *curl[NUM_HANDLES] = {0};
   int running;
   CURLM *m = NULL;
   int i;
   char target_url[256];
   char dnsentry[256];
-  struct curl_slist *slist = NULL;
+  struct curl_slist *slist = NULL, *slist2;
   char *port = libtest_arg3;
   char *address = libtest_arg2;
 
@@ -46,14 +46,17 @@ 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);
-    slist = curl_slist_append(slist, dnsentry);
+    slist2 = curl_slist_append(slist, dnsentry);
+    if(!slist2) {
+      fprintf(stderr, "curl_slist_append() failed\n");
+      goto test_cleanup;
+    }
+    slist = slist2;
   }
 
-  for(i=0; i < NUM_HANDLES; i++)
-    curl[i] = NULL;
-
   start_test_timing();
 
   global_init(CURL_GLOBAL_ALL);
@@ -67,8 +70,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 */
@@ -112,6 +116,7 @@ int test(char *URL)
 
       abort_on_test_timeout();
     }
+    wait_ms(1); /* to ensure different end times */
   }
 
 test_cleanup: