• Daniel Veillard's avatar
    Fix potential crash on entities errors · 28f5e1a2
    Daniel Veillard authored
    Related to https://bugs.launchpad.net/lxml/+bug/502959
    
    Basically the core of the issue is that if an entity references another
    entity, then in case we are replacing entities content, we should always
    do so by copying the referenced content as long as the reference is
    done within the entity. Otherwise, if for some reason there is a later
    parsing error that entity content may be freed.
    
    Complex scenario exposed by command:
    thinkpad:~/XML/diveintopython-5.4/xml -> valgrind --db-attach=yes
    ../../xmllint --loaddtd --noout --noent diveintopython.xml
    
      Document references &a;
      a references &b;
      we references b content directly in by linking in the a content
      a has an error further down
      we free a, freeing the chunk from b
      Document references &b; after &a;
      we try to copy b content, but it was freed already => segfault
    
    * parser.c: never reference directly entity content without copying if
      we aren't in the document main entity
    28f5e1a2