Menu

#23 XMLDoc_parse_buffer_DOM bug

v4.2.8
closed-fixed
None
5
2018-09-07
2018-08-14
Ermanno
No

Hi Matthieu,
I'm using sxmlc lib to read some xml. I receive an error parsing the xml attached. The call chain is:

XMLDoc_parse_buffer_DOM(.. , .. , &doc);
XMLDoc_root(&doc);

The problem is that when XMLDoc_parse_buffer_DOM fails, it calls XMLDoc_free(&doc) and, so, when I call XMLDoc_root it fails as doc is not initialized.

The error is returned by this last function, and is "simple:65: An error was found (UNEXPECTED_TAG_END), loading aborted..."

This error is identified in function _parse_data_SAX into if (txt_end == NULL) { } body.

After testing I've notice that the problem is the '+' char at the end of tag <msginerr>. If I remove it all works. So if there is a '+' char at the end of the value field of a tag, _parse_data_SAX fails.</msginerr>

Thanks for support,

Ermanno

1 Attachments

Discussion

  • Matthieu Labas

    Matthieu Labas - 2018-08-14
    • status: open --> accepted
    • Group: v4.2.7 --> v4.2.8
     
  • Matthieu Labas

    Matthieu Labas - 2018-08-14

    Hi Ermanno,
    Thank you for your report and the XML file. I will have a look asap.
    Matthieu

     
  • Ermanno

    Ermanno - 2018-08-14

    Update: also if you replace the last '+' with '=' it not works.

     
  • Matthieu Labas

    Matthieu Labas - 2018-08-17

    Hi Ermanno,

    The following code I am using works fine:

    FILE* f = fopen("/tmp/TmRejection.xml", "r");
    fseek(f, 0, SEEK_END);
    long n = ftell(f);
    fseek(f, 0, SEEK_SET);
    char* buf = malloc(n+1);
    fread(buf, 1, n, f);
    buf[n] = 0; // <<<---
    fclose(f);
    XMLDoc doc;
    XMLDoc_init(&doc);
    XMLDoc_parse_buffer_DOM(buf, "simple", &doc);
    XMLNode* root = XMLDoc_root(&doc);
    XMLNode_print(root, stdout, NULL, NULL, 0, 0, 0);
    

    There is indeed a problem when the buffer is not NULL-terminated (if you remove the line marked with <<<---). I will correct it by adding a len parameter.

    Could you paste the code you use that shows the error?

    Thanks,
    Matthieu

     
  • Matthieu Labas

    Matthieu Labas - 2018-08-17

    (which means I suspect the buffer you're parsing is just enough to contain the whole XML and is not null-terminated. Removing a character somewhere will make room for the null termination and make things work)

     
  • Ermanno

    Ermanno - 2018-08-17

    Hi Matthieu,
    yesterday evening I detect the problem by debugging. I solve it by using a calloc instead of malloc, so that the buffer is already well terminated. So we are reaching the same problem.

    Thanks,
    Ermanno

     
  • Matthieu Labas

    Matthieu Labas - 2018-09-07
    • status: accepted --> closed-fixed
     
  • Matthieu Labas

    Matthieu Labas - 2018-09-07

    v4.2.8 delivered.

     

Log in to post a comment.