From 6b01c5148dc0e643d35b0c2725991689b9c4a123 Mon Sep 17 00:00:00 2001 From: Mattias Ellert 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 e25d8f2a2ba..42cce9a30c2 100644 --- a/src/XrdCl/XrdClLocalFileHandler.cc +++ b/src/XrdCl/XrdClLocalFileHandler.cc @@ -664,6 +664,12 @@ namespace XrdCl std::unique_ptr 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 );