]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
squidclient: Better error checking
authorAmos Jeffries <squid3@treenet.co.nz>
Fri, 30 Nov 2012 13:19:14 +0000 (06:19 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Fri, 30 Nov 2012 13:19:14 +0000 (06:19 -0700)
* detect and report fstat() errors which could lead to invalid
  Content-Length being sent.

* remove some useless checks which were causing false positives by Coverity.

 Detected by Coverity Scan. Issues 740334, 740379

tools/squidclient.cc

index 6d204743f0d84106e4aee6b15781be033888da52..5347cd0f8a46e5a7529a7321673f4084217dae30 100644 (file)
@@ -268,13 +268,11 @@ main(int argc, char *argv[])
                 break;
 
             case 'A':
-                if (optarg != NULL)
-                    useragent = optarg;
+                useragent = optarg;
                 break;
 
             case 'h':          /* remote host */
-                if (optarg != NULL)
-                    hostname = optarg;
+                hostname = optarg;
                 break;
 
             case 'j':
@@ -282,13 +280,11 @@ main(int argc, char *argv[])
                 break;
 
             case 'V':
-                if (optarg != NULL)
-                    version = optarg;
+                version = optarg;
                 break;
 
             case 'l':          /* local host */
-                if (optarg != NULL)
-                    localhost = optarg;
+                localhost = optarg;
                 break;
 
             case 's':          /* silent */
@@ -421,7 +417,9 @@ main(int argc, char *argv[])
         setmode(put_fd, O_BINARY);
 #endif
 
-        fstat(put_fd, &sb);
+        if (fstat(put_fd, &sb) < 0) {
+            fprintf(stderr, "%s: can't identify length of file (%s)\n", argv[0], xstrerror());
+        }
     }
 
     if (!host) {