Skip to content

Commit

Permalink
Fix crash in setKernelArgSVMPointer
Browse files Browse the repository at this point in the history
In case std::map::lower_bound() returns std::map::end(),
we have to go to previos iterator (last one in the map)
before address inspection

Signed-off-by: Igor Venevtsev <igor.venevtsev@intel.com>
  • Loading branch information
ivvenevt committed May 15, 2024
1 parent c6a4022 commit db83c65
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions intercept/src/intercept.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7419,13 +7419,18 @@ void CLIntercept::setKernelArgSVMPointer(
{
std::lock_guard<std::mutex> lock(m_Mutex);

if (m_SVMAllocInfoMap.empty())
{
return;
}

// Unlike clSetKernelArg(), which must pass a cl_mem, clSetKernelArgSVMPointer
// can pass a pointer to the base of a SVM allocation or anywhere inside of
// an SVM allocation. As a result, we need to search the SVM map to find the
// base address and size of the SVM allocation.

CSVMAllocInfoMap::iterator iter = m_SVMAllocInfoMap.lower_bound( arg );
if( iter->first != arg && iter != m_SVMAllocInfoMap.begin() )
if( iter == m_SVMAllocInfoMap.end() || (iter->first != arg && iter != m_SVMAllocInfoMap.begin()) )
{
// Go to the previous iterator.
--iter;
Expand All @@ -7449,8 +7454,13 @@ void CLIntercept::setKernelArgUSMPointer(
{
std::lock_guard<std::mutex> lock(m_Mutex);

if (m_SVMAllocInfoMap.empty())
{
return;
}

CUSMAllocInfoMap::iterator iter = m_USMAllocInfoMap.lower_bound( arg );
if( iter->first != arg && iter != m_USMAllocInfoMap.begin() )
if( iter == m_USMAllocInfoMap.end() || (iter->first != arg && iter != m_USMAllocInfoMap.begin()) )
{
// Go to the previous iterator.
--iter;
Expand Down

0 comments on commit db83c65

Please sign in to comment.