Opened 4 years ago

Closed 4 years ago

Last modified 21 months ago

#454 closed defect (fixed)

template engine raises PROGRAM_ERROR

Reported by: Maxim Reznik Owned by:
Priority: major Milestone: 18.0
Component: Matreshka - XML Processor Version: 0.7.0
Keywords: tamper with cursors Cc:

Description

When I run template parser (as descibed in XML/Templates):

      --  Process template.
      
      Reader.Parse;

I get error:

Exception name: PROGRAM_ERROR
Message: XML.Templates.Streams.XML_Stream_Element_Vectors.Append: attempt to tamper with cursors (vector is busy)

Here is backtrace:

#0  <__gnat_debug_raise_exception> (e=0xa1ff00 <program_error>) at s-excdeb.adb:43
#1  0x00007f4816be5e31 in ada.exceptions.complete_occurrence (x=x@entry=0x7f480c037290) at a-except.adb:924
#2  0x00007f4816be5e3d in ada.exceptions.complete_and_propagate_occurrence (x=x@entry=0x7f480c037290) at a-except.adb:933
#3  0x00007f4816be5e92 in <__gnat_raise_exception> (e=0xa1ff00 <program_error>, message=...) at a-except.adb:975
#4  0x00007f48148a9327 in xml.templates.streams.xml_stream_element_vectors.append (count=1, new_item=..., container=...) at /home/max/net/gnat-gpl-2015/lib/gcc/x86_64-pc-linux-gnu/4.9.3/adainclude/a-convec.adb:476
#5  0x00007f48148c00a9 in xml.templates.streams.xml_stream_element_vectors.append (count=1, new_item=..., container=...) at /home/max/net/gnat-gpl-2015/lib/gcc/x86_64-pc-linux-gnu/4.9.3/adainclude/a-convec.adb:487
#6  xml.templates.processors.characters (self=..., text=..., success=<optimized out>) at /home/max/net/matreshka/source/xml/templates/xml-templates-processors.adb:101
#7  0x00007f48148bbf72 in xml.templates.processors.process_stream (self=..., stream=..., success=success@entry=true) at /home/max/net/matreshka/source/xml/templates/xml-templates-processors.adb:428
#8  0x00007f48148cbbe1 in xml.templates.processors.end_element (self=..., namespace_uri=..., local_name=..., qualified_name=..., success=true) at /home/max/net/matreshka/source/xml/templates/xml-templates-processors.adb:271
#9  0x00007f48176cdbd0 in xml.sax.simple_readers.callbacks.call_end_element (self=..., namespace_uri=<optimized out>, local_name=local_name@entry=0x7f480c033a40, qualified_name=qualified_name@entry=0x7f480c032be0) at /home/max/net/matreshka/source/xml/sax/xml-sax-simple_readers-callbacks.adb:172
#10 0x00007f48176db74e in xml.sax.simple_readers.parser.actions.on_end_tag (self=..., symbol=<optimized out>) at /home/max/net/matreshka/source/xml/sax/xml-sax-simple_readers-parser-actions.adb:414
#11 0x00007f4817662f12 in xml.sax.simple_readers.parser.yyparse (self=...) at /home/max/net/matreshka/source/xml/sax/xml/xml-sax-simple_readers-parser.adb:922
#12 0x00007f48176abe27 in xml.sax.simple_readers.parse (self=...) at /home/max/net/matreshka/source/xml/sax/xml-sax-simple_readers.adb:352
#13 0x00007f4814c53b34 in servlets.main_menu.render (self=..., user=..., menu=...) at /home/max/net/beard/source/web/servlets/servlets-main_menu.adb:295
#14 0x00007f4814c44834 in servlets.main_menu.do_get (self=..., request=..., response=...) at /home/max/net/beard/source/web/servlets/servlets-main_menu.adb:124
#15 0x00007f481814c457 in matreshka.servlet_containers.dispatch (self=0xa20680 <servlet.application.container>, request=0x7f4815a93b70, response=0x7f4815a94088, <selfL>=0) at /home/max/net/matreshka/source/web/spikedog/core/matreshka-servlet_containers.adb:192
#16 0x000000000042e63a in matreshka.servlet_servers.aws_servers.request_callback (request=...) at /home/max/net/frame/source/servlet/aws/matreshka-servlet_servers-aws_servers.adb:126
#17 0x000000000050d273 in aws.dispatchers.callback.dispatch (dispatcher=..., request=...) at /home/max/net/aws/src/core/aws-dispatchers-callback.adb:58
#18 0x00000000005be77c in aws.server.http_utils.answer_to_client.build_answer () at /home/max/net/aws/src/core/aws-server-http_utils.adb:187
#19 0x00000000005bcf06 in aws.server.http_utils.answer_to_client (http_server=..., line_index=3, c_stat=..., socket_taken=false, will_close=false) at /home/max/net/aws/src/core/aws-server-http_utils.adb:339
#20 0x000000000069666e in aws.server.protocol_handler (la=...) at /home/max/net/aws/src/core/aws-server-protocol_handler.adb:235
#21 0x0000000000693174 in aws.server.line (<_task>=0x1e6a200) at /home/max/net/aws/src/core/aws-server.adb:319
#22 0x00007f4817083b22 in system.tasking.stages.task_wrapper () from /home/max/net/frame/.objs/aws_server/../../../gnat-gpl-2015/lib/gcc/x86_64-pc-linux-gnu/4.9.3/rts-native/adalib/libgnarl-2015.so

Template:

<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml' xmlns:mtl='http://forge.ada-ru.org/matreshka/template'>
  <head>
    <title>Семантична база даних</title>
    <link rel='stylesheet' type='text/css' href='/static/index.css'/>
    <link rel='icon' type='image/png' href='favicon.png'/>
  </head>
  <body>
    ${user}
    <div style="clear: both;"/>
    <div class="main-form">
      <ul>
        <mtl:for expression="item of menu">
          <li>
            <a href="">${item.text}</a>
            <mtl:if expression="item.is_submenu">
              <ul class="hidden">
                <mtl:for expression="subitem of item.submenu">
                  <li><a href="">${subitemitem.text}</a></li>
                </mtl:for>
              </ul>
            </mtl:if>
          </li>
        </mtl:for>
       </ul> 
    </div>
  </body>
</html>

Change History (6)

comment:1 by Maxim Reznik, 4 years ago

Reproducer:

  • main.adb
with Ada.Wide_Wide_Text_IO;

with League.Holders.Booleans;
with League.Holders.JSON_Arrays;
with League.JSON.Arrays;
with League.JSON.Objects;
with League.JSON.Values;
with League.Strings;
with XML.SAX.Input_Sources.Streams.Files;
with XML.SAX.Output_Destinations.Strings;
with XML.SAX.Pretty_Writers;
with XML.SAX.Simple_Readers;
with XML.Templates.Processors;

procedure Main is
   Input  : aliased XML.SAX.Input_Sources.Streams.Files.File_Input_Source;
   Reader : aliased XML.SAX.Simple_Readers.Simple_Reader;
   Filter : aliased XML.Templates.Processors.Template_Processor;
   Writer : aliased XML.SAX.Pretty_Writers.XML_Pretty_Writer;
   Output : aliased XML.SAX.Output_Destinations.Strings
     .String_Output_Destination;
   Post   : League.JSON.Objects.JSON_Object;
   Posts  : League.JSON.Arrays.JSON_Array;

begin
   Input.Open_By_File_Name
    (League.Strings.To_Universal_String ("page.xml.tmpl"));

   --  Configure reader.

   Reader.Set_Input_Source (Input'Unchecked_Access);
   Reader.Set_Content_Handler (Filter'Unchecked_Access);
   Reader.Set_Lexical_Handler (Filter'Unchecked_Access);

   --  Configure template processor.

   Filter.Set_Content_Handler (Writer'Unchecked_Access);
   Filter.Set_Lexical_Handler (Writer'Unchecked_Access);

   Post.Insert
    (League.Strings.To_Universal_String ("submenu"),
     Posts.To_JSON_Value);
   Posts.Append (Post.To_JSON_Value);
   Filter.Set_Parameter
    (League.Strings.To_Universal_String ("posts"),
     League.Holders.JSON_Arrays.To_Holder (Posts));

   --  Configure XML writer.

   Writer.Set_Output_Destination (Output'Unchecked_Access);

   --  Process template.

   Reader.Parse;

   --  Output result.

   Ada.Wide_Wide_Text_IO.Put (Output.Get_Text.To_Wide_Wide_String);
end Main;
  • page.xml.tmpl
    <html xmlns='http://www.w3.org/1999/xhtml' xmlns:mtl='http://forge.ada-ru.org/matreshka/template'>
      <body>
        <mtl:for expression="item of posts">
          <mtl:for expression="subitem of item.submenu">
          </mtl:for>
        </mtl:for>
      </body>
    </html>
    

comment:2 by vadim.godunko, 4 years ago

In 5555:

Fix processing of nested loops.

Refs #454.

comment:3 by vadim.godunko, 4 years ago

In 5556:

Add automated test.

Refs #454.

comment:4 by vadim.godunko, 4 years ago

Resolution: fixed
Status: newclosed

comment:5 by vadim.godunko, 4 years ago

In 5561:

Run automated test.

Refs #454.

comment:6 by vadim.godunko, 21 months ago

Milestone: 0.8.018.0

Milestone renamed

Note: See TracTickets for help on using tickets.