Uploaded image for project: 'Xerces-C++'
  1. Xerces-C++
  2. XERCESC-2253

Undefined behavior on ElemStack and NamespaceScope

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.2.5
    • 3.3.0
    • Miscellaneous
    • 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.

      Attachments

        Activity

          People

            scantor Scott Cantor
            dieortin Diego Ortín
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: