Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
3.2.5
-
None
-
gcc-12, C++17
Description
When running programs that use xerces-c with the Undefined Behavior Sanitizer (ubsan), undefined behavior is detected in ElemStack::expandStack and NamespaceScope::expandMap. Both instances are 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)
I can send a simple patch that fixes this.