[xmlsec] About xmlParseInNodeContext() in libxml2.

StackWD(hotmail) StackWD at hotmail.com
Tue Sep 14 23:41:32 PDT 2004


Hi!
   
   There is an example. The buffer is what I want to parse, the NS xsi is defined in soap.xml.
===========================================================================================
    char *buffer = "<xsi:getsumReturn xsi:type=\"xsd:int\">9</xsi:getsumReturn>";

    xmlInitParser();
    LIBXML_TEST_VERSION
    xmlLoadExtDtdDefaultValue = XML_DETECT_IDS | XML_COMPLETE_ATTRS;
    xmlSubstituteEntitiesDefault(1);

    /* load template */
    doc = xmlParseFile("soap.xml");
    if ((doc == NULL) || (xmlDocGetRootElement(doc) == NULL)){
        fprintf(stderr, "Error: unable to parse file \"%s\"\n", "soap.xml");
        goto done;
    }

    ret = xmlParseInNodeContext(xmlDocGetRootElement(doc), buffer, xmlStrlen(buffer), XML_PARSE_NOENT, &encNode);
    if(ret < 0) {
        fprintf(stderr, "Error: xmlParseInNodeContext.\n");
        goto done;
    }

    xmlAddChild(xmlDocGetRootElement(doc), encNode);
    xmlDocDump(stdout, doc);

    xmlFreeDoc(doc);  <----- The error : Segmentation fault occur!
==============================================================================================

soap.xml
===========================================
<?xml version="1.0" encoding="UTF-8"?>
<Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"></Envelope>
===========================================

  BTW, I use function xmlParseInNodeContext() because after encrypt node <xsi:getsumReturn xsi:type="xsd:int">9</xsi:getsumReturn>, the xsi NS will not found when decrypt it. If you have another good method I will replace it.
  Thx!


>Do you do "unlink" node before freeing it? If you do then
>it sounds like a libxml2 bug but it's hard to say something
>definite without a reproducible test case. Can you provide
>a *small* example that demonstrates the problem?
>
>Aleksey
>
>StackWD(hotmail) wrote:
>> Hi!
>> 
>> Let me tell you more details. I parse from a buffer, such as "<xsi:getsumReturn xsi:type="xsd:int">9</xsi:getsumReturn>". 
>> If the content of this node is a single character or a single digital or a serials of blank, then use xmlFreeNode() to free the node that via function xmlParseInNodeContext() , the result will be Segmentation fault. I debug into xmlFreeNode() and trace to DICT_FREE(cur->content), the cur->content is 9 and execute xmlFree((char *)(str)) result in the error of Segmentation fault. If the content of this node is NOT a single character or a single digital or a serials of blank, there will be right all.
>> I think whether I omit something or other? I need your help. Thx for lot.
>> 
>> 
>> 
>>>Try to run the program under gdb or valgrind and find out
>>>what causes the crash. BTW, did you call xmlSetTreeDoc?
>>>
>>>Aleksey
>>>
>>>
>>>
>>>StackWD(hotmail) wrote:
>>>
>>>
>>>>Hi!
>>>>
>>>>    I have a question about function xmlParseInNodeContext() in libxml2.6.13. After I finished call it and get a parsed XML chain and add it to the doc, then there is an error Segmentation fault when I use xmlFreeDoc() to free the doc. I compiled in Red Hat 9 and need some advice from you. Thx!
>>>>_______________________________________________
>>>>xmlsec mailing list
>>>>xmlsec at aleksey.com
>>>>http://www.aleksey.com/mailman/listinfo/xmlsec
>> 
>> 
>> 
>>         StackWD(hotmail)
>>         StackWD at hotmail.com
>>           2004-09-15
>> 
>> _______________________________________________
>> xmlsec mailing list
>> xmlsec at aleksey.com
>> http://www.aleksey.com/mailman/listinfo/xmlsec


        StackWD(hotmail)
        StackWD at hotmail.com
          2004-09-15



More information about the xmlsec mailing list