]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
squidclient: Fix missing error handling on PUT
authorAmos Jeffries <squid3@treenet.co.nz>
Thu, 2 Mar 2017 14:44:26 +0000 (03:44 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Thu, 2 Mar 2017 14:44:26 +0000 (03:44 +1300)
 Detected by Coverity Scan. Issue 1364710

tools/squidclient/squidclient.cc

index 1b17e12c322debe13323909f37cfaf2eac3f2e57..7b821d848ddeacad96eefdaf36fc941564246dce 100644 (file)
@@ -569,16 +569,19 @@ main(int argc, char *argv[])
         if (put_file) {
             debugVerbose(1, "Sending HTTP request payload ...");
             int x;
-            lseek(put_fd, 0, SEEK_SET);
-            while ((x = read(put_fd, buf, sizeof(buf))) > 0) {
+            if ((x = lseek(put_fd, 0, SEEK_SET)) < 0) {
+                int xerrno = errno;
+                std::cerr << "ERROR: lseek: " << xstrerr(xerrno) << std::endl;
 
-                x = Transport::Write(buf, x);
+            } else while ((x = read(put_fd, buf, sizeof(buf))) > 0) {
 
-                total_bytes += x;
+                    x = Transport::Write(buf, x);
 
-                if (x <= 0)
-                    break;
-            }
+                    total_bytes += x;
+
+                    if (x <= 0)
+                        break;
+                }
 
             if (x != 0)
                 std::cerr << "ERROR: Cannot send file." << std::endl;