From 686663c8f8ee77bb7d9d8335e9739919120ece03 Mon Sep 17 00:00:00 2001 From: Andrew Hanushevsky Date: Thu, 15 Oct 2020 16:35:12 -0700 Subject: [PATCH] [Server] Avoid SEGV when checksum response is invalid. --- src/XrdPosix/XrdPosixAdmin.cc | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/XrdPosix/XrdPosixAdmin.cc b/src/XrdPosix/XrdPosixAdmin.cc index 1683c62f24a..aae14b076e2 100644 --- a/src/XrdPosix/XrdPosixAdmin.cc +++ b/src/XrdPosix/XrdPosixAdmin.cc @@ -105,16 +105,17 @@ int XrdPosixAdmin::Query(XrdCl::QueryCode::Code reqCode, void *buff, int bsz) // if (!XrdPosixMap::Result(Xrd.Query(reqCode, reqBuff, rspBuff))) {uint32_t rspSz = rspBuff->GetSize(); - // if the string is null-terminated decrement the size char *rspbuff = rspBuff->GetBuffer(); - if ( !(rspbuff[rspSz - 1]) ) --rspSz; - if (bsz >= (int)rspSz + 1) - {strncpy((char *)buff, rspbuff, rspSz); - ((char*)buff)[rspSz] = 0; // make sure the string is null-terminated - delete rspBuff; - return static_cast(rspSz + 1); - } - errno = ERANGE; + if (rspbuff && rspSz) + {// if the string is null-terminated decrement the size + if ( !(rspbuff[rspSz - 1]) ) --rspSz; + if (bsz >= (int)rspSz + 1) + {strncpy((char *)buff, rspbuff, rspSz); + ((char*)buff)[rspSz] = 0; // make sure it is null-terminated + delete rspBuff; + return static_cast(rspSz + 1); + } else errno = ERANGE; + } else errno = EFAULT; } // Return error