]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - test-suite/tcp-banger2.c
Source Format Enforcement (#532)
[thirdparty/squid.git] / test-suite / tcp-banger2.c
index b15eea4244c84c5010c096a4a5ed7f8487d2f234..5e5cd77b204162c624ba6766e89a5854311fe12b 100644 (file)
@@ -1,6 +1,12 @@
-#include "squid.h"
+/*
+ * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
 
-/* $Id$
+#include "squid.h"
 
 /*
  * On some systems, FD_SETSIZE is set to something lower than the
@@ -36,9 +42,6 @@
 #if HAVE_UNISTD_H
 #include <unistd.h>
 #endif
-#if HAVE_STDIO_H
-#include <stdio.h>
-#endif
 #if HAVE_FCNTL_H
 #include <fcntl.h>
 #endif
@@ -256,7 +259,7 @@ void
 reply_done(int fd, void *data)
 {
     struct _request *r = data;
-    if (opt_range);            /* skip size checks for now */
+    if (opt_range);     /* skip size checks for now */
     else if (strcmp(r->method, "HEAD") == 0);
     else if (r->bodysize != r->content_length && r->content_length >= 0)
         fprintf(stderr, "ERROR: %s got %d of %d bytes\n",
@@ -331,7 +334,7 @@ request(char *urlin) {
         checksum = "-";
     r = calloc(1, sizeof *r);
     assert(r != NULL);
-    r->url = strdup(url);
+    r->url = xstrdup(url);
     assert(r->url);
     strcpy(r->method, method);
     strcpy(r->requestbodyfile, file);
@@ -339,29 +342,29 @@ request(char *urlin) {
     if (size && strcmp(size, "-") != 0)
         r->validsize = atoi(size);
     else
-        r->validsize = -1;     /* Unknown */
+        r->validsize = -1;  /* Unknown */
     if (checksum && strcmp(checksum, "-") != 0)
         r->validsum = strtoul(checksum, NULL, 0);
     if (status)
         r->validstatus = atoi(status);
-    r->content_length = -1;    /* Unknown */
+    r->content_length = -1; /* Unknown */
     if (opt_accel) {
         host = strchr(url, '/') + 2;
         url = strchr(host, '/');
     } else {
         host = NULL;
     }
-    sprintf(msg, "%s %s HTTP/1.0\r\n", method, url);
+    snprintf(msg, sizeof(msg)-1, "%s %s HTTP/1.0\r\n", method, url);
     if (host) {
         url[0] = '\0';
-        sprintf(buf, "Host: %s\r\n", host);
+        snprintf(buf, sizeof(buf)-1, "Host: %s\r\n", host);
         strcat(msg, buf);
         url[0] = '/';
     }
     strcat(msg, "Accept: */*\r\n");
     if (opt_ims && (lrand48() & 0x03) == 0) {
         w = time(NULL) - (lrand48() & 0x3FFFF);
-        sprintf(buf, "If-Modified-Since: %s\r\n", mkrfc850(&w));
+        snprintf(buf, sizeof(buf)-1, "If-Modified-Since: %s\r\n", mkrfc850(&w));
         strcat(msg, buf);
     }
     if (file && strcmp(file, "-") != 0) {
@@ -371,7 +374,7 @@ request(char *urlin) {
             exit(1);
         }
         fstat(f, &st);
-        sprintf(buf, "Content-Length: %d\r\n", (int) st.st_size);
+        snprintf(buf, sizeof(buf)-1, "Content-Length: %d\r\n", (int) st.st_size);
         strcat(msg, buf);
     }
     if (opt_range && (lrand48() & 0x03) == 0) {
@@ -384,13 +387,13 @@ request(char *urlin) {
                 strcat(msg, ",");
             switch (lrand48() & 0x03) {
             case 0:
-                sprintf(buf, "-%d", len);
+                snprintf(buf, sizeof(buf)-1, "-%d", len);
                 break;
             case 1:
-                sprintf(buf, "%d-", offset);
+                snprintf(buf, sizeof(buf)-1, "%d-", offset);
                 break;
             default:
-                sprintf(buf, "%d-%d", offset, offset + len);
+                snprintf(buf, sizeof(buf)-1, "%d-%d", offset, offset + len);
                 break;
             }
             strcat(msg, buf);
@@ -482,10 +485,10 @@ char *argv[];
     struct timeval to;
     setbuf(stdout, NULL);
     setbuf(stderr, NULL);
-    progname = strdup(argv[0]);
+    progname = xstrdup(argv[0]);
     gettimeofday(&now, NULL);
     start = last = now;
-    custom_header = strdup("");
+    custom_header = xstrdup("");
     while ((c = getopt(argc, argv, "ap:h:H:n:icrl:L:t:")) != -1) {
         switch (c) {
         case 'a':
@@ -495,7 +498,7 @@ char *argv[];
             proxy_port = atoi(optarg);
             break;
         case 'h':
-            proxy_addr = strdup(optarg);
+            proxy_addr = xstrdup(optarg);
             break;
         case 'n':
             max_connections = atoi(optarg);
@@ -592,3 +595,4 @@ char *argv[];
     printf("Exiting normally\n");
     return 0;
 }
+