[erlang-bugs] bug_xmerl_invalid_attribute

Anthony Ramine <>
Thu Oct 31 11:42:32 CET 2013


I don't understand. What is the bug?

That xmerl crashes on malformed input sounds like a feature to me, not a bug.

-- 
Anthony Ramine

> Le 31 oct. 2013 à 05:01, Constantin Malikov <> a écrit :
> 
> Hello , friends. I want to tell you about a bug in Erlang:
> 
> I have a trouble with validating xml document by xsd schema in case of
> one of the attribute have incorrect record in the xml document. I attached simple sample, where you can see this problem. To run it, compile xml_attribute_test.erl and invoke “invalid_xml_test” method.
> You can see the error message:
> _________________________________________________________________
> ** exception error: no function clause matching
> xmerl_scan:scan_att_value("a>\n <rule>\n <result>\n <continue context=\"ctx_megaco_local_in\"/>\n <!-- continue context=\"ctx_megaco_local_in\"/ -->\n </result>\n </rule>\n</context>\n",
> {xmerl_scanner,undefined,no,prolog,[],undefined,internal,
> true,false,false,49173,false,false,
> "/home/konstantin/erlang/tasks/diffR15B02/xml_invalid_attribute_test",
> undefined,[],file_name_unknown,off,[],preserve,
> #Fun<xmerl_scan.0.5757651>,#Fun<xmerl_scan.1.5757651>,
> #Fun<xmerl_scan.2.5757651>,#Fun<xmerl_scan.3.5757651>,
> #Fun<xmerl_scan.4.5757651>,#Fun<xmerl_scan.5.5757651>,
> #Fun<xmerl_scan.6.5757651>,...},
> 'CDATA') (xmerl_scan.erl, line 2343)
> in function xmerl_scan:scan_element/12 (xmerl_scan.erl, line 2147)
> in call from xmerl_scan:scan_document/2 (xmerl_scan.erl, line 571)
> in call from xmerl_scan:string/2 (xmerl_scan.erl, line 287)
> in call from xml_attribute_test:read_xml/1 (xml_attribute_test.erl, line 13)
> in call from xml_attribute_test:invalid_xml_test/0 (xml_attribute_test.erl, line 17) 
> ________________________________________________________________
> 
> How can i see, in the xmerl_scan.erl module, scan_att_value metod. No function for processing incorrect attribute record.
> 
> Tested by Erlang 16B02, xmerl 1.3.4 and R15B02, xmerl 1.3.2.
> 
> _______________________ctx_megaco.xml____________________________
> <? xml version = "1.0"?>
> <context digit=a>
>     <rule>
>         <result>
>             <continue context="ctx_megaco_local_in"/>
>             <! - Continue context = "ctx_megaco_local_in" / ->
>         </ result>
>     </ rule>
> </ context>
> ________________________________________________________________
> 
> _________________________ecss_routing.xsd__________________________
> <? xml version = "1.0" encoding = "UTF- 8" ? >
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
>   
>   <xs:element name="context">
>     <xs:complexType>
>       <xs:sequence>
>         <xs:element name="rule">
>           <xs:complexType>
>             <xs:sequence>
>               <xs:element name="result">
>                 <xs:complexType>
>                   <xs:choice>
>                     <xs:element name="incomplete" type="xs:string"/>
>                     <! - xs: element name = "no_route" type = "nullType" / ->
>                     <xs:element name="continue" type="continueType"/>
>                   </ xs: choice>
>                 </ xs: complexType>
>               </ xs: element>
>             </ xs: sequence>
>           </ xs: complexType>
>         </ xs: element>
>       </ xs: sequence>
>     </ xs: complexType>
>   </ xs: element>
>  
>   <xs:complexType name="continueType">
>     <xs:attribute name="context" type="xs:string"/>
>   </ xs: complexType>
> </ xs: schema>
> ________________________________________________________________
> 
> _______________________xml_attribute_test.erl__________________________
> 
> -module (xml_attribute_test).
> 
> -export ([
>          invalid_xml_test / 0
>         ]).
> 
> read_xml (FileName) ->
>     {ok, Schema} = xmerl_xsd: process_schema ("ecss_routing.xsd"),
>     {ok, BXml} = file: read_file (FileName),
>     Xml = erlang: binary_to_list (BXml),
>     {XmerXml, _} = xmerl_scan: string (Xml),
>     xmerl_xsd: validate (XmerXml, Schema).
> 
> invalid_xml_test () ->
>     Result = read_xml ("ctx_megaco.xml"),
>     io: format ("~ p ~ n", [Result]).
> ________________________________________________________________
> 
> I can offer the option of a patch that fixes this problem. The person who is responsible for supporting ssh has the discretion to take it as it is, or can make own fix.
> ________________________________________________________________
> --- xmerl-1.3.2/src/xmerl_scan.erl	2013-10-26 14:25:25.000000000
> +++ xmerl-1.3.2.1/src/xmerl_scan.erl	2013-10-26 13:03:42.000000000
> @@ -2373,13 +2373,16 @@
> scan_att_value([H|T], S0,'CDATA'=AT) when H == $"; H == $' ->
> ?bump_col(1),
> scan_att_chars(T, S, H, [],[], AT,false);
> scan_att_value([H|T], S0,AttType) when H == $"; H == $' ->
> ?bump_col(1),
> {T1,S1,IsNorm} = normalize(T,S,false),
> - scan_att_chars(T1, S1, H, [],[], AttType,IsNorm).
> + scan_att_chars(T1, S1, H, [],[], AttType,IsNorm);
> +%% EltexPatch: prevent function_clause exception
> +scan_att_value([H|_], S0, _AttType) ->
> + ?fatal({unexpected_char, H}, S0).
> scan_att_chars([],S=#xmerl_scanner{continuation_fun=F},H,Acc,TmpAcc,AT,IsNorm)->
> ?dbg("cont()...~n", []),
> F(fun(MoreBytes, S1) ->
> scan_att_chars(MoreBytes, S1, H, Acc,TmpAcc,AT,IsNorm)
> end,
> ________________________________________________________________
> 
> With best regards,
> Malikov Constantin, software developer, Eltex.
> <xml_invalid_attribute.tar.gz>
> _______________________________________________
> erlang-bugs mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-bugs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20131031/ecfef5da/attachment-0001.html>


More information about the erlang-bugs mailing list