Blob Blame History Raw
From fe2224d33b0c310e19d497e6e795f779c8e88001 Mon Sep 17 00:00:00 2001
From: Guilherme Amadio <amadio@cern.ch>
Date: Thu, 30 Nov 2023 10:02:03 +0100
Subject: [PATCH] Reapply "[XrdCl] Make sure error message does not include a
 null-character."

This reverts commit 5a832596a59d1055f59620d43fbb740955ce6787.
Even though commit 9987b4b41990df69ae611a523acb76c69eeccbbb did fix
an error message that had a second null termination character, reverting
this change was a mistake, as this change is actually still needed to
avoid the single terminating null byte in error messages from appearing
in the output of the client.

Closes: #2138
---
 src/XrdCl/XrdClXRootDMsgHandler.cc | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/XrdCl/XrdClXRootDMsgHandler.cc b/src/XrdCl/XrdClXRootDMsgHandler.cc
index 1bd60a3e3..81e41d21b 100644
--- a/src/XrdCl/XrdClXRootDMsgHandler.cc
+++ b/src/XrdCl/XrdClXRootDMsgHandler.cc
@@ -1202,7 +1202,9 @@ namespace XrdCl
       if( pStatus.code == errErrorResponse )
       {
         st->errNo = rsp->body.error.errnum;
-        std::string errmsg( rsp->body.error.errmsg, rsp->hdr.dlen-4 );
+        // omit the last character as the string returned from the server
+        // (acording to protocol specs) should be null-terminated
+        std::string errmsg( rsp->body.error.errmsg, rsp->hdr.dlen-5 );
         if( st->errNo == kXR_noReplicas && !pLastError.IsOK() )
           errmsg += " Last seen error: " + pLastError.ToString();
         st->SetErrorMessage( errmsg );
-- 
2.43.0