Blob Blame History Raw
From fde7669ff9006495034a493386c72d080158f027 Mon Sep 17 00:00:00 2001
From: Mattias Ellert <mattias.ellert@physics.uu.se>
Date: Wed, 22 Nov 2023 19:29:12 +0100
Subject: [PATCH] If extended attributes are not supported xattr->Get() returns
 -ENOTSUP. When this small negative value is cast to a size_t in the call to
 new on the following line it becomes a very large integer and the request to
 allocate this enormous memory block fails with a std::bad_alloc exception.

This commit adds a check on the returned size and returns an error if
it is negative avoiding triggering the std::bad_alloc exception.
---
 src/XrdCl/XrdClLocalFileHandler.cc | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/XrdCl/XrdClLocalFileHandler.cc b/src/XrdCl/XrdClLocalFileHandler.cc
index e25d8f2a2..42cce9a30 100644
--- a/src/XrdCl/XrdClLocalFileHandler.cc
+++ b/src/XrdCl/XrdClLocalFileHandler.cc
@@ -664,6 +664,12 @@ namespace XrdCl
       std::unique_ptr<char[]> buffer;
 
       int size = xattr->Get( name.c_str(), 0, 0, 0, fd );
+      if( size < 0 )
+      {
+        XRootDStatus status( stError, errLocalError, -size );
+        response.push_back( XAttr( *itr, "", status ) );
+        continue;
+      }
       buffer.reset( new char[size] );
       int ret = xattr->Get( name.c_str(), buffer.get(), size, 0, fd );
 
-- 
2.43.0