GithubHelp home page GithubHelp logo

sxmlc's People

Contributors

cliffbaumann avatar emergreanimator avatar gvollant avatar jeaeberle avatar matthieu-labas avatar ptrks avatar raldone01 avatar sometimesfood avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

sxmlc's Issues

Memory leak in XMLSearch_free()

search->next is not being freed in XMLSearch_free().

if (free_next && search->next != NULL) {
    (void)XMLSearch_free(search->next, true);
    __free(search->next);     <---- this line needs to be added
    search->next = NULL;
}

simple xpath not working?

Hello!

I've been trying out sxmlc and I'm encountering problems with using the xpath support. It could very well be that I'm just using it wrong! :)

I've got a simple xml file and I want to get at an element that I know where it is.

<?xml blah blah blah?>
<video>
   <mode>1</mode>
</video>

I want to get at the text in the node. I'm trying XMLSearch_init_from_XPath() but I can't seem to find the correct format for the xpath text. I've tried "video/mode" and "/video/mode" but while the result returns 1 the contents of the nodes in the search have no text. Even if I put in a garbage path "adfladkfj" it still returns 1.

So, how to do I format the xpath string so that I can directly get the node?

Thanks!

Feature request: can we have support for XMLNode_add_sibling()?

Hello Matthieu,

First of all thanks for this library. It look very good for reading existing XML, and creating XML documents from scratch.

There's some lack of support for modifying existing (loaded) XML documents. There's only one method to add a node, which is XMLNode_add_child(). This is fine when creating XML documents from scratch, but sometimes you need to add a node next to another one, right in that position, not at the end of all the children nodes of the father.

Have you ever thought about this feature? Can we expect to have it in a near future? Is there any current workaround to bypass this?

Thanks in advance. Best regards.

A few suggestions

Hello Matthieu. While trying to use sxmlc on Linux, I found these 3 little things:

  • In
    int XML_parse_attribute_to(const SXML_CHAR* str, int to, XMLAttribute* xmlattr)
    maybe change
    SXML_CHAR quote;
    to
    SXML_CHAR quote='\0'
    (variable used without initialisation)

  • Maybe rename
    #define sx_strdup __strdup
    to
    #define sx_strdup __sx_strdup
    because it is already defined in /usr/include/bits/string2.h

  • Variable ch could be used without being initialised in read_line_alloc(). Maybe set it to EOF here:
    if ((c = mgetc(in)) == EOF) { ch = EOF; break;

Free node->text before overwriting it?

Hello Matthieu, I'm not sure if this is actually an issue.

I've observed that when you're trying to replace the text on an XMLNode, you don't free previously allocated memory (by sx_strdup()). Is this a correct behaviour?

image

Best regards, D.

Getting non-expected values after compiling for x64 (MinGW)

Hello Matthieu,

I keep on using this lib. I compiled the code with MinGW x64 and found out that i.e.: node->n_children misleads the actual value of children number, it usually returns a very high number, i.e.: 108708416. Worth to mention that with MinGW x86 works perfect.

valgrind detects errors in XMLSearch_init

==5753== Conditional jump or move depends on uninitialised value(s)
==5753== at 0x40150E: XMLSearch_init (sxmlsearch.c:58)
==5753== by 0x4021C8: XMLSearch_init_from_XPath (sxmlsearch.c:385)
==5753== by 0x4013F3: main (main.cpp:12)

==5753== LEAK SUMMARY:
==5753== definitely lost: 85 bytes in 3 blocks
==5753== indirectly lost: 0 bytes in 0 blocks
==5753== possibly lost: 0 bytes in 0 blocks
==5753== still reachable: 0 bytes in 0 blocks
==5753== suppressed: 0 bytes in 0 blocks

Used test code:

#include "sxmlc.h"
#include "sxmlsearch.h"

int main() {

    XMLSearch search;
    SXML_CHAR* xpath2 = NULL;
    const SXML_CHAR xpath[] = C2SX("/tagFather[@name, @id!='0', .='toto*']/tagChild[.='text', @attrib='value']");

    if (XMLSearch_init_from_XPath(xpath, &search))
        printf("%s\n %s\n", xpath, XMLSearch_get_XPath_string(&search, &xpath2, '\''));
    else
        printf("Error\n");
    XMLSearch_free(&search, true);
    
    return 0;
}

why can't I find all tags.. what can be problem ..

why can't I find all tags.. what can be problem ..

void display_recursive_children_content(XMLNode*source  , int children_count, char* names) {
	for (int i = 0; i < source->n_children; i++) {
		XMLNode *child = source->children[i];
		int new_children = child->n_children;
		if (new_children > 0) {
			char s[100];
			if (child->n_attributes == 0)
			{
				strcat(names, " ");
				strcat(names, child->tag);
				//printf(" n%s", names);
				//printf("  %s", child->text);
			}
			else
				printf(" \n %s", child->tag);
			for (int j = 0; j < child->n_attributes; j++)
			{
				strcpy(s, names);
				strcat(s, " ");
				strcat(s, child->attributes[j].name);
				strcat(s, ": ");
				strcat(s, child->attributes[j].value);

				printf(" %s", child->attributes[j].name);
				printf(" %s", child->attributes[j].value);
			}
			display_recursive_children_content(child, new_children, s);
		}
		else {
			printf("   %s", names);
			printf("   %s", child->tag);
			printf("   %s", child->text);
		}
	}
}

Originally posted by @embbo in #16 (comment)

text content is not escaped

Hi, it looks like html2str is not called on text content, only on attributes. Is this the expected behavior?

SEGV in DOMXMLDoc_node_end at sxmlc.c:1600

Describe the bug
A bad xml file which can lead XMLDoc_parse_file_DOM to segmentation fault.

Poc here :
segv1.zip

To Reproduce

  1. Build the whole project with ASAN
  2. Drive programs (compile it with ASAN too):
// driver.c
#include "sxmlc.h"
#include "sxmlsearch.h"

int main(int argc, char** argv){
	
	if(argc!=2) return 0;
	
	XMLDoc doc;
	XMLDoc_init(&doc);
	XMLDoc_parse_file_DOM(argv[1], &doc);
	XMLDoc_free(&doc);
	return 0;
}
  1. Run Poc:
$ ./driver ./segv1

Expected behavior
Parse the xml file without segmentation fault because segmentation fault can cause a Denial of Service (Dos).

Environment (please complete the following information):

  • System and Version : Ubuntu 18.04 + gcc 7.5.0
  • commit version: 87bb134

Additional context
ASAN says:

$ ./driver segv1
ASAN:DEADLYSIGNAL
=================================================================
==127014==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7f568dd6ee1a bp 0x7ffd78b77380 sp 0x7ffd78b76ae0 T0)
==127014==The signal is caused by a READ memory access.
==127014==Hint: address points to the zero page.
    #0 0x7f568dd6ee19  (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x59e19)
    #1 0x7f568daf602b in DOMXMLDoc_node_end /home/ubuntu/some_c_test/sxmlc/src/sxmlc.c:1600
    #2 0x7f568dafbb45 in _parse_data_SAX /home/ubuntu/some_c_test/sxmlc/src/sxmlc.c:1515
    #3 0x7f568daf85cd in XMLDoc_parse_file_SAX /home/ubuntu/some_c_test/sxmlc/src/sxmlc.c:1780
    #4 0x7f568dafe74c in XMLDoc_parse_file_DOM_text_as_nodes /home/ubuntu/some_c_test/sxmlc/src/sxmlc.c:1831
    #5 0x55ce76aa2d99 in main /home/ubuntu/some_c_test/sxmlc/fuzz/driver.cpp:10
    #6 0x7f568d70bc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)
    #7 0x55ce76aa2e89 in _start (/home/ubuntu/some_c_test/sxmlc/fuzz/driver+0xe89)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x59e19) 
==127014==ABORTING

search specific data in string .. key --> value

@matthieu-labas
I am trying to find specific data from xml string, I tried myself but i faild . do you have any idea or clue how can I do that ..
for example I have this string ...

<UAVariable BrowseName="1:DeviceName" DataType="String" NodeId="ns=1;i=2005" ParentNodeId="ns=1;i=2001"> <DisplayName>DeviceName</DisplayName> <Description>DeviceName</Description> <References> <Reference IsForward="false" ReferenceType="HasComponent">ns=1;i=2001</Reference> <Reference ReferenceType="HasTypeDefinition">i=63</Reference> </References> <Value> <uax:String>MyName</uax:String> </Value> </UAVariable>

I can read this sting but I want to read values of BrowseName, DataType, NodeId .... which are 1:DeviceName ..String and ns=1;i=2005 repectively

Like Key --> value

Tag by Tag

Hi, I am using sxmlc Parsor which is really good for my Micro controller, but my question is it possible if I can parsor tag by tag instead of whole xml. beacuse my micro controller ihave low memory ..

for example .
Ist it just copy these Tags
<UAObject NodeId="i=20002" BrowseName="0:Control" ParentNodeId="i=85"> ..... ...... .... </UAObject>

than next tags

... ... ...

Pars data from STRING

Hi all, I just started sxmlc with the example and it works perfectly but I want to read an xml string NOT a file from out side..any clue how can i do that .. like this

string xml = "mo<daily dayFrequency=""1"" />2012-10-31T10:00:00Z";

Regards

SEGV in freadBOM at sxmlc.c:2294

Describe the bug
A bad xml file which can lead XMLDoc_parse_file_DOM to segmentation fault.

Poc here :
segv2.zip

To Reproduce

  1. Build the whole project with ASAN
  2. Drive programs (compile it with ASAN too):
// driver.c
#include "sxmlc.h"
#include "sxmlsearch.h"

int main(int argc, char** argv){
	
	if(argc!=2) return 0;
	
	XMLDoc doc;
	XMLDoc_init(&doc);
	XMLDoc_parse_file_DOM(argv[1], &doc);
	XMLDoc_free(&doc);
	return 0;
}
  1. Run Poc:
$ ./driver ./segv2

Expected behavior
Parse the xml file without segmentation fault because segmentation fault can cause a Denial of Service (Dos).

Environment (please complete the following information):

  • System and Version : Ubuntu 18.04 + gcc 7.5.0
  • commit version: 87bb134

Additional context
ASAN says:

$ ./driver segv2
ASAN:DEADLYSIGNAL
=================================================================
==30894==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000002 (pc 0x7f0ae710f525 bp 0x7ffda877adb0 sp 0x7ffda877acc0 T0)
==30894==The signal is caused by a WRITE memory access.
==30894==Hint: address points to the zero page.
    #0 0x7f0ae710f524 in freadBOM /home/chan/some_c_test/sxmlc/src/sxmlc.c:2294
    #1 0x7f0ae710e4be in XMLDoc_parse_file_SAX /home/chan/some_c_test/sxmlc/src/sxmlc.c:1760
    #2 0x7f0ae711474c in XMLDoc_parse_file_DOM_text_as_nodes /home/chan/some_c_test/sxmlc/src/sxmlc.c:1831
    #3 0x564f36dfdd99 in main /home/chan/some_c_test/sxmlc/fuzz/driver.cpp:10
    #4 0x7f0ae6d21c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)
    #5 0x564f36dfde89 in _start (/home/chan/some_c_test/sxmlc/fuzz/driver+0xe89)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/chan/some_c_test/sxmlc/src/sxmlc.c:2294 in freadBOM
==30894==ABORTING

reading from EPROM

Hi i am reading from eeprom and i get string without any problem . but when i parse, it doesn't recognize the string .. its like this
char buffer[1024];
printf buffer :

but if i declare string in same fiuntion it works fine.

char buffer[] = "\n"............

      XMLDoc doc;
 XMLDoc_init(&doc);
 XMLDoc_parse_buffer_DOM(buffer, "test1", &doc);
 XMLNode* root;
 root = doc.nodes[doc.i_root];

 char* root_name = (char*)malloc(strlen(root->tag));
 strcpy(root_name, root->tag);


 display_recursive_children_content(root, root->n_children, root->tag);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.