From 9f465e1e546c7ded6b59c28bfa0530ea35c3f21b Mon Sep 17 00:00:00 2001
From: Gerardo Ganis <Gerardo.Ganis@cern.ch>
Date: Mon, 15 May 2017 15:14:11 +0200
Subject: [PATCH] Fix for coverity #94544 #42570 #42571 #42628 #54956 #54963

---
 proof/proof/src/TProof.cxx             | 2 +-
 proof/proofd/src/XrdProofConn.cxx      | 8 ++++++--
 proof/proofd/src/XrdProofSched.cxx     | 4 ++++
 proof/proofd/src/proofexecv.cxx        | 2 +-
 proof/proofplayer/src/TProofPlayer.cxx | 2 +-
 proof/proofx/src/TXSocket.cxx          | 2 +-
 6 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/proof/proof/src/TProof.cxx b/proof/proof/src/TProof.cxx
index e54d9d0aab3..f4e8d57b043 100644
--- a/proof/proof/src/TProof.cxx
+++ b/proof/proof/src/TProof.cxx
@@ -897,7 +897,7 @@ Int_t TProof::Init(const char *, const char *conffile,
 
    if (IsMaster()) {
       // to make UploadPackage() method work on the master as well.
-      fPackMgr = gProofServ->GetPackMgr();
+      if (gProofServ) fPackMgr = gProofServ->GetPackMgr();
    } else {
 
       TString sandbox;
diff --git a/proof/proofd/src/XrdProofConn.cxx b/proof/proofd/src/XrdProofConn.cxx
index 3ea07ba07b2..6ed838995df 100644
--- a/proof/proofd/src/XrdProofConn.cxx
+++ b/proof/proofd/src/XrdProofConn.cxx
@@ -1296,8 +1296,12 @@ XrdSecProtocol *XrdProofConn::Authenticate(char *plist, int plsiz)
    //
    // Prepare the parms object
    char *bpar = (char *)malloc(plsiz + 1);
-   if (bpar)
-      memcpy(bpar, plist, plsiz);
+   if (!bpar) {
+      TRACE(XERR, "unable to allocate buffer for parameters");
+      return protocol;
+   }
+
+   memcpy(bpar, plist, plsiz);
    bpar[plsiz] = 0;
    XrdSecParameters Parms(bpar, plsiz + 1);
 
diff --git a/proof/proofd/src/XrdProofSched.cxx b/proof/proofd/src/XrdProofSched.cxx
index 997c8494c02..460622ed438 100644
--- a/proof/proofd/src/XrdProofSched.cxx
+++ b/proof/proofd/src/XrdProofSched.cxx
@@ -402,6 +402,10 @@ int XrdProofSched::GetWorkers(XrdProofdProofServ *xps,
 
    int rc = 0;
 
+   // The caller must provide a proofserv session handler
+   if (!xps)
+      return -1;
+
    TRACE(REQ, "enter: query tag: "<< ((querytag) ? querytag : ""));
 
    // Static or dynamic
diff --git a/proof/proofd/src/proofexecv.cxx b/proof/proofd/src/proofexecv.cxx
index db1ed9cf51d..2576e24fa39 100644
--- a/proof/proofd/src/proofexecv.cxx
+++ b/proof/proofd/src/proofexecv.cxx
@@ -641,11 +641,11 @@ int exportsock(rpdunix *conn)
       int natt = 1000;
       while (natt > 0 && (fd = dup(d)) <= 2) {
          if (fd != d) close(fd);
+         fd = -1;
          natt--;
       }
       if (natt <= 0 && fd <= 2) {
          Info("exportsock: ERROR: no free filedescriptor!");
-         if (fd != d) close(fd);
          close(d);
          return -1;
       }
diff --git a/proof/proofplayer/src/TProofPlayer.cxx b/proof/proofplayer/src/TProofPlayer.cxx
index 8a33e286945..1f6419000f5 100644
--- a/proof/proofplayer/src/TProofPlayer.cxx
+++ b/proof/proofplayer/src/TProofPlayer.cxx
@@ -4408,7 +4408,7 @@ Bool_t TProofPlayerSlave::HandleTimer(TTimer *)
    m << fb;
 
    // send message to client;
-   gProofServ->GetSocket()->Send(m);
+   if (gProofServ) gProofServ->GetSocket()->Send(m);
 
    delete fb;
 
diff --git a/proof/proofx/src/TXSocket.cxx b/proof/proofx/src/TXSocket.cxx
index deaf0e3434d..2836d312ec0 100644
--- a/proof/proofx/src/TXSocket.cxx
+++ b/proof/proofx/src/TXSocket.cxx
@@ -2135,7 +2135,7 @@ Int_t TXSocket::Reconnect()
    if (gDebug > 0) {
       Info("Reconnect", "%p (c:%p, v:%d): trying to reconnect to %s (logid: %d)",
                         this, fConn, (fConn ? fConn->IsValid() : 0),
-                        fUrl.Data(), fConn->GetLogConnID());
+                        fUrl.Data(), (fConn ? fConn->GetLogConnID() : -1));
    }
 
    Int_t tryreconnect = gEnv->GetValue("TXSocket.Reconnect", 0);
-- 
GitLab