From 93120b8d0b0ecaa3dee1ecdcdf4cfaddaff998e1 Mon Sep 17 00:00:00 2001 From: Amos Jeffries Date: Fri, 3 Mar 2017 03:44:26 +1300 Subject: [PATCH] squidclient: Fix missing error handling on PUT Detected by Coverity Scan. Issue 1364710 --- tools/squidclient/squidclient.cc | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/tools/squidclient/squidclient.cc b/tools/squidclient/squidclient.cc index 1b17e12c32..7b821d848d 100644 --- a/tools/squidclient/squidclient.cc +++ b/tools/squidclient/squidclient.cc @@ -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; -- 2.47.3