Hi,
Attached patch fixed an error in the xmlreader.
If a text attribute contained a ", but not at the end of the string it could fail.
For example this (minimal) xml file: <?xml version="1.0"?> <CONFIG Value=""TEST"." />
TestProgram:
program testxmlcfg;
{$mode objfpc}{$H+}uses Classes, SysUtils, xmlcfg;
var AFilename: string;
begin
AFileName:= 'test.xml';
try
XMLConfig:=TXMLConfig.Create(AFilename);
finally
XMLConfig.Free;
end;
end.It crashed if run with heaptrc and gave error if run with valgrind, but not with the patch applied.
Regards, Vincent.
Index: fcl/xml/xmlread.pp
===================================================================
RCS file: /FPC/CVS/fpc/fcl/xml/xmlread.pp,v
retrieving revision 1.16
diff -u -r1.16 xmlread.pp
--- fcl/xml/xmlread.pp 14 Mar 2005 21:10:12 -0000 1.16
+++ fcl/xml/xmlread.pp 2 May 2005 11:17:58 -0000
@@ -1297,8 +1297,10 @@
predefined in XML: }
procedure TXMLReader.ResolveEntities(RootNode: TDOMNode);
+var
+ Node, NextNode: TDOMNode;
- procedure ReplaceEntityRef(EntityNode: TDOMNode; const Replacement: String);
+ procedure ReplaceEntityRef(EntityNode: TDOMNode; const Replacement: string);
var
PrevSibling, NextSibling: TDOMNode;
begin
@@ -1310,6 +1312,8 @@
RootNode.RemoveChild(EntityNode);
if Assigned(NextSibling) and (NextSibling.NodeType = TEXT_NODE) then
begin
+ // next sibling is to be removed, so we can't use it anymore
+ NextNode := NextSibling.NextSibling;
TDOMCharacterData(PrevSibling).AppendData(
TDOMCharacterData(NextSibling).Data);
RootNode.RemoveChild(NextSibling);
@@ -1323,13 +1327,11 @@
RootNode.ReplaceChild(Doc.CreateTextNode(Replacement), EntityNode);
end;
-var
- Node, NextSibling: TDOMNode;
begin
Node := RootNode.FirstChild;
while Assigned(Node) do
begin
- NextSibling := Node.NextSibling;
+ NextNode := Node.NextSibling;
if Node.NodeType = ENTITY_REFERENCE_NODE then
if Node.NodeName = 'amp' then
ReplaceEntityRef(Node, '&')
@@ -1341,7 +1343,7 @@
ReplaceEntityRef(Node, '<')
else if Node.NodeName = 'quot' then
ReplaceEntityRef(Node, '"');
- Node := NextSibling;
+ Node := NextNode;
end;
end;
_______________________________________________ fpc-devel maillist - [email protected] http://lists.freepascal.org/mailman/listinfo/fpc-devel
