Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with empty values in leaf-list #46

Closed
achernavin22 opened this issue Oct 26, 2018 · 1 comment
Closed

Issue with empty values in leaf-list #46

achernavin22 opened this issue Oct 26, 2018 · 1 comment

Comments

@achernavin22
Copy link

achernavin22 commented Oct 26, 2018

Suppose we have this field:

leaf-list ip {
    type inet:ipv4-prefix;
    ...
}
  1. Assign one valid IP via REST (PUT "ip": "1.1.1.1/32" or "ip": ["1.1.1.1/32"])
  2. Assign empty IP via REST (PUT "ip": "" or "ip": [""])
  3. Segmentation fault
#0  __strcmp_sse42 () at ../sysdeps/x86_64/multiarch/strcmp-sse42.S:165
#1  0x00007f63252be163 in xml_cmp1 () from /lib64/libclixon.so.3
#2  0x00007f63252be4c3 in xml_search1 () from /lib64/libclixon.so.3
#3  0x00007f63252be5ee in xml_search () from /lib64/libclixon.so.3
#4  0x00007f63252bed75 in match_base_child () from /lib64/libclixon.so.3
#5  0x00007f63252c0271 in xml_diff1 () from /lib64/libclixon.so.3
#6  0x00007f63252c039b in xml_diff1 () from /lib64/libclixon.so.3
#7  0x00007f63252c039b in xml_diff1 () from /lib64/libclixon.so.3
#8  0x00007f63252c039b in xml_diff1 () from /lib64/libclixon.so.3
#9  0x00007f63252c039b in xml_diff1 () from /lib64/libclixon.so.3
#10 0x00007f63252c056a in xml_diff () from /lib64/libclixon.so.3
#11 0x00000000004083cf in validate_common ()
#12 0x0000000000408680 in candidate_commit ()
#13 0x0000000000408876 in from_client_commit ()
#14 0x0000000000407cef in from_client_msg ()
#15 0x0000000000408094 in from_client ()
#16 0x00007f63252b9fe4 in event_loop () from /lib64/libclixon.so.3
#17 0x0000000000405102 in main ()

OR

#0  __strcmp_sse42 () at ../sysdeps/x86_64/multiarch/strcmp-sse42.S:165
#1  0x00007f4b296cdfef in xml_cmp () from /lib64/libclixon.so.3
#2  0x00007f4b290fdd59 in msort_with_tmp (p=0x7ffdfe1beb50, b=0x1664310, n=2) at msort.c:83
#3  0x00007f4b290fe04c in msort_with_tmp (n=2, b=0x1664310, p=0x7ffdfe1beb50) at msort.c:45
#4  __GI___qsort_r (b=0x1664310, n=2, s=8, cmp=0x7f4b296cdeae <xml_cmp>, arg=<optimized out>) at msort.c:297
#5  0x00007f4b296ce27a in xml_sort () from /lib64/libclixon.so.3
#6  0x00007f4b296cd75c in xml_apply () from /lib64/libclixon.so.3
#7  0x00007f4b296cd795 in xml_apply () from /lib64/libclixon.so.3
#8  0x00007f4b296cd795 in xml_apply () from /lib64/libclixon.so.3
#9  0x00007f4b296cd795 in xml_apply () from /lib64/libclixon.so.3
#10 0x00007f4b296cd852 in xml_apply0 () from /lib64/libclixon.so.3
#11 0x0000000000406421 in from_client_edit_config ()
#12 0x0000000000407a89 in from_client_msg ()
#13 0x0000000000408094 in from_client ()
#14 0x00007f4b296c9fe4 in event_loop () from /lib64/libclixon.so.3
#15 0x0000000000405102 in main ()

This patch seems to solve the problem:

diff --git a/lib/src/clixon_xml_sort.c b/lib/src/clixon_xml_sort.c
index e3aa4b2..9731909 100644
--- a/lib/src/clixon_xml_sort.c
+++ b/lib/src/clixon_xml_sort.c
@@ -144,6 +144,12 @@ xml_cmp(const void* arg1,
        return 0; /* Ordered by user: maintain existing order */
     switch (y1->ys_keyword){
     case Y_LEAF_LIST: /* Match with name and value */
+       b1 = xml_body(x1);
+       b2 = xml_body(x2);
+       if (b1 == NULL || b2 == NULL) {
+           equal = 1;
+           break;
+       }
        equal = strcmp(xml_body(x1), xml_body(x2));
        break;
     case Y_LIST: /* Match with key values 
@@ -203,7 +209,8 @@ xml_cmp1(cxobj        *x,
     case Y_LEAF_LIST: /* Match with name and value */
        if (userorder && yang_find((yang_node*)y, Y_ORDERED_BY, "user") != NULL)
            *userorder=1;
-       b=xml_body(x);
+       if ((b = xml_body(x)) == NULL)
+           break; /* error case */
        match = strcmp(keyval[0], b);
        break;
     case Y_LIST: /* Match with array of key values */
olofhagsand added a commit that referenced this issue Oct 27, 2018
@olofhagsand
Copy link
Member

Empty leaf-list values was not thought about in this code. The same omission may appear elsewhere. Thanks for detecting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants