Monday, 10 December 2012

Bug in libdom

#include <stdio.h>
#include <stdlib.h>

#include <dom/dom.h>
#include <dom/bindings/hubbub/parser.h>

int main(int argc, char *argv[])
{
dom_exception exc;
dom_document *doc;
dom_element *element;
dom_string *tag_name;
bool is_equal;

/* Create the document */
exc = dom_implementation_create_document(DOM_IMPLEMENTATION_HTML,
NULL, NULL, NULL,
NULL, &doc);

if (exc != DOM_NO_ERR) {
printf("Can't create DOM document\n");
return EXIT_FAILURE;
}

/* Create DOM string */
exc = dom_string_create("html", sizeof("html"), &tag_name);

if (exc != DOM_NO_ERR) {
printf("Failed to create DOM string\n");
return EXIT_FAILURE;
}

/* Create element */
exc = dom_document_create_element(doc, tag_name, &element);

if (exc != DOM_NO_ERR) {
printf("Failed to create element");
return EXIT_FAILURE;
}

exc = dom_node_is_equal(element, element, &is_equal);

if (exc != DOM_NO_ERR) {
printf("Failed to compare");
return EXIT_FAILURE;
}

printf("Nodes are %s\n", is_equal ? "the same" : "not the same");

dom_node_unref(element);

return EXIT_SUCCESS;
}
Hi there,

I think I found a bug in the dom_string_isequal function in core/string.c.

The attached testcode (isequal-test.c) will generate a segfault.

The code works as expected (at least for me) after attached patch is applied.

Kind regards,

David Pavlotzky

No comments:

Post a Comment