Patch for fixing WriteXML() which gives Access Violation errors
Original Reporter info from Mantis: ggeldenhuys
-
Reporter name: Graeme Geldenhuys
Original Reporter info from Mantis: ggeldenhuys
- Reporter name: Graeme Geldenhuys
Description:
Writing the following code will cause WriteXML() to crash out with an AV.
FXMLDoc: TDOMDocument;
FXMLDoc := TDOMDocument.Create;
... then later in your program....
WriteXML(FXMLDoc, FAppPath + FDocName); <-- AV here
I don't set any "processing instructions" or stylesheets in the FXMLDoc
instance.
The problem was that inside
procedure TXMLWriter.VisitDocument(node: TDOMNode);
the code never tested node to see if it is a TXMLDocument type, it just assumed that it is, then forced a typecast and tries to access a TXMLDocument specific field. The patch simply does a test first, to see that node is the correct type, then only does it try to access the fields.
Seeing that this is a bugfix as well, any chance this can be back-ported to 2.4.3 - for those with production code that doesn't use FPC 2.5.1 for day-to-day work.
Backtrace showing the problem:
------------------------------------------------------------
&LtPos;snip more application output>
****** output goes to:
/opt/dailybuilds/tiopf/UnitTests/Text/textrunner64.xml
Program received signal SIGSEGV, Segmentation fault.
0x00000000004eab45 in VISITDOCUMENT (this=0x7ffff7f367c0, NODE=0x7ffff7f27040)
at ../../../../fpc-2.4.3/src/packages/fcl-xml/src/xmlwrite.pp:684
684 if Length(TXMLDocument(node).StylesheetType) > 0 then
(gdb) bt
#0 0x00000000004eab45 in VISITDOCUMENT (this=0x7ffff7f367c0,
NODE=0x7ffff7f27040)
at ../../../../fpc-2.4.3/src/packages/fcl-xml/src/xmlwrite.pp:684
#1 0x00000000004e99b1 in WRITENODE (this=0x7ffff7f367c0, NODE=0x7ffff7f27040)
at ../../../../fpc-2.4.3/src/packages/fcl-xml/src/xmlwrite.pp:406
#2 0x00000000004eb2b1 in WRITEXMLFILE (DOC=0x7ffff7f27040,
ASTREAM=0x7ffff55640c0)
at ../../../../fpc-2.4.3/src/packages/fcl-xml/src/xmlwrite.pp:836
#3 0x00000000004eb0f4 in WRITEXMLFILE (DOC=0x7ffff7f27040,
AFILENAME=0x7ffff6854890
'/opt/dailybuilds/tiopf/UnitTests/Text/textrunner64.xml')
at ../../../../fpc-2.4.3/src/packages/fcl-xml/src/xmlwrite.pp:809
#4 0x00000000004eb2fd in WRITEXML (ELEMENT=0x7ffff7f27040,
AFILENAME=0x7ffff6854890
'/opt/dailybuilds/tiopf/UnitTests/Text/textrunner64.xml')
at ../../../../fpc-2.4.3/src/packages/fcl-xml/src/xmlwrite.pp:844
#5 0x00000000005002fd in TESTINGENDS (this=0x7ffff7f53840,
TESTRESULT=0x7ffff7f82058)
at ../../../../git/dunit2/src/XMLListener.pas:451
#6 0x00000000004fc09a in TESTINGENDS (this=0x7ffff7f539c0)
at ../../../../git/dunit2/src/TestFrameworkProxy.pas:1228
#7 0x000000000048125e in EXECSTATUSUPDATER (this=0x7ffff7f69040,
ATEST=0x7ffff7f69148)
at ../../../../git/dunit2/src/TestFramework.pas:3733
#8 0x0000000000475377 in SET_EXECSTATUS (this=0x7ffff7f69040, VALUE=_FAILED)
at ../../../../git/dunit2/src/TestFramework.pas:2108
#9 0x0000000000478dc9 in RUN (this=0x7ffff7f69040, EXECCONTROL=0x7ffff7f82108)
at ../../../../git/dunit2/src/TestFramework.pas:2819
#10 0x0000000000481a63 in RUN (this=0x7ffff7f69040, EXECCONTROL=0x7ffff7f82108)
at ../../../../git/dunit2/src/TestFramework.pas:3798
#11 0x00000000004f961b in RUN (this=0x7ffff7fed6c0, TESTRESULT=0x7ffff7f82058)
at ../../../../git/dunit2/src/TestFrameworkProxy.pas:883
#12 0x00000000004f5d70 in RUNTEST (SUITE=0x7ffff7fed730, LISTENERS=...,
highLISTENERS=1)
at ../../../../git/dunit2/src/TestFrameworkProxy.pas:322
#13 0x000000000048a3cf in TIRUNTEST (SUITE=0x7ffff7fed730,
EXITBEHAVIOR=RXBCONTINUE)
at ../../UnitTests/Common/tiTextTestRunner.pas:158
#14 0x000000000048a784 in RUNREGISTEREDTESTS (EXITBEHAVIOR=RXBCONTINUE)
at ../../UnitTests/Common/tiTextTestRunner.pas:198
#15 0x000000000042e163 in main () at
../../UnitTests/Text/dunit2_fpc_textrunner.lpr:28
------------------------------------------------------------
Mantis conversion info:
- Mantis ID: 18048
- OS: Ubuntu Linux
- OS Build: 10.04
- Platform: x86_64
- Version: 2.5.1
- Fixed in version: 2.4.4
- Fixed in revision: 16785 (#f3147ae1)
- Target version: 3.0.0