Fix potential crash on entities errors

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
1 file changed
tree: 83f64c64fd35873b40687b88b58bbaadff0c46e4
  1. bakefile/
  2. doc/
  3. example/
  4. include/
  5. macos/
  6. optim/
  7. python/
  8. result/
  9. test/
  10. vms/
  11. VxWorks/
  12. win32/
  13. xstc/
  14. .cvsignore
  15. .gitignore
  16. acinclude.m4
  17. AUTHORS
  18. autogen.sh
  19. buf.c
  20. buf.h
  21. build_glob.py
  22. c14n.c
  23. catalog.c
  24. ChangeLog
  25. check-relaxng-test-suite.py
  26. check-relaxng-test-suite2.py
  27. check-xinclude-test-suite.py
  28. check-xml-test-suite.py
  29. check-xsddata-test-suite.py
  30. chvalid.c
  31. chvalid.def
  32. configure.in
  33. Copyright
  34. dbgen.pl
  35. dbgenattr.pl
  36. debugXML.c
  37. dict.c
  38. DOCBparser.c
  39. elfgcchack.h
  40. enc.h
  41. encoding.c
  42. entities.c
  43. error.c
  44. genChRanges.py
  45. gentest.py
  46. genUnicode.py
  47. global.data
  48. globals.c
  49. HACKING
  50. hash.c
  51. HTMLparser.c
  52. HTMLtree.c
  53. INSTALL.libxml2
  54. legacy.c
  55. libxml-2.0-uninstalled.pc.in
  56. libxml-2.0.pc.in
  57. libxml.3
  58. libxml.h
  59. libxml.m4
  60. libxml.spec.in
  61. libxml2.doap
  62. libxml2.syms
  63. list.c
  64. MAINTAINERS
  65. Makefile.am
  66. Makefile.tests
  67. Makefile.win
  68. nanoftp.c
  69. nanohttp.c
  70. NEWS
  71. parser.c
  72. parserInternals.c
  73. pattern.c
  74. README
  75. README.cvs-commits
  76. README.tests
  77. regressions.py
  78. regressions.xml
  79. relaxng.c
  80. rngparser.c
  81. runsuite.c
  82. runtest.c
  83. runxmlconf.c
  84. save.h
  85. SAX.c
  86. SAX2.c
  87. schematron.c
  88. testapi.c
  89. testAutomata.c
  90. testC14N.c
  91. testchar.c
  92. testdict.c
  93. testdso.c
  94. testHTML.c
  95. testlimits.c
  96. testModule.c
  97. testOOM.c
  98. testOOMlib.c
  99. testOOMlib.h
  100. testReader.c
  101. testrecurse.c
  102. testRegexp.c
  103. testRelax.c
  104. testSAX.c
  105. testSchemas.c
  106. testThreads.c
  107. testThreadsWin32.c
  108. testURI.c
  109. testXPath.c
  110. threads.c
  111. timsort.h
  112. TODO
  113. TODO_SCHEMAS
  114. tree.c
  115. trio.c
  116. trio.h
  117. triodef.h
  118. trionan.c
  119. trionan.h
  120. triop.h
  121. triostr.c
  122. triostr.h
  123. uri.c
  124. valid.c
  125. xinclude.c
  126. xlink.c
  127. xml2-config.1
  128. xml2-config.in
  129. xml2Conf.sh.in
  130. xmlcatalog.c
  131. xmlIO.c
  132. xmllint.c
  133. xmlmemory.c
  134. xmlmodule.c
  135. xmlreader.c
  136. xmlregexp.c
  137. xmlsave.c
  138. xmlschemas.c
  139. xmlschemastypes.c
  140. xmlstring.c
  141. xmlunicode.c
  142. xmlwriter.c
  143. xpath.c
  144. xpointer.c
  145. xzlib.c
  146. xzlib.h