[PR] Fix undefined behavior on ElemStack [xerces-c]

dieortin (via GitHub) <[email protected]> Wed, 28 Aug 2024 09:29:57 -0000
Newsgroups gmane.text.xml.xerces-c.devel
Message-ID <[email protected]>
dieortin opened a new pull request, #59:
URL: https://github.com/apache/xerces-c/pull/59

   The Undefined Behavior Sanitizer detects undefined behavior in `ElemStack::expandStack`. This is due to `memcpy` being called with NULL as one of its parameters when `toExpand->fMap` is NULL, which works (the size parameter is 0) but is undefined behavior.
   
   This is fixed by doing a simple check for null before calling `memcpy`. If the object we wanted to copy from was null, we do not copy at all and the result is the same. This avoids the UBSan being triggered, and potential issues with compiler optimizations (as both pointer arguments to `memcpy` are marked as `__nonnull`)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]