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

null pointer for ns_set when calling lyd_parse_opaq_error #2075

Closed
lyzliyuzhi91 opened this issue Aug 7, 2023 · 4 comments
Closed

null pointer for ns_set when calling lyd_parse_opaq_error #2075

lyzliyuzhi91 opened this issue Aug 7, 2023 · 4 comments
Labels
is:bug Bug description. status:completed From the developer perspective, the issue was solved (bug fixed, question answered,...)

Comments

@lyzliyuzhi91
Copy link

lyzliyuzhi91 commented Aug 7, 2023

for (uint32_t u = ns_set->count - 1; u + 1 > 0; --u) {

#0  0x00007ffff6ed3465 in lyxml_ns_get (ns_set=0x0, prefix=0x0, prefix_len=0) at /data/lcx/opensource/libyang/src/xml.c:248
#1  0x00007ffff6e0bd9a in ly_store_prefix_data (ctx=0x7ffff0019760, value=0x7ffff0015570, value_len=0, format=LY_VALUE_XML,
    prefix_data=0x0, format_p=0x55555579fe7c, prefix_data_p=0x55555579fe80)
    at /data/lcx/opensource/libyang/src/tree_data_common.c:1393
#2  0x00007ffff6ec98c6 in lyplg_type_prefix_data_new (ctx=0x7ffff0019760, value=0x7ffff0015570, value_len=0, format=LY_VALUE_XML,
    prefix_data=0x0, format_p=0x55555579fe7c, prefix_data_p=0x55555579fe80) at /data/lcx/opensource/libyang/src/plugins_types.c:595
#3  0x00007ffff6efd700 in lyplg_type_store_union (ctx=0x7ffff0019760, type=0x7ffff068c6c0, value=0x7ffff0015570, value_len=0,
    options=0, format=LY_VALUE_XML, prefix_data=0x0, hints=64, ctx_node=0x7ffff06af9f0, storage=0x7fffffffd3f0, unres=0x0,
    err=0x7fffffffd418) at /data/lcx/opensource/libyang/src/plugins_types/union.c:342
#4  0x00007ffff6e08fce in ly_value_validate (ctx=0x7ffff0019760, node=0x7ffff06af9f0, value=0x7ffff0015570 "", value_len=0,
    format=LY_VALUE_XML, prefix_data=0x0, hints=64) at /data/lcx/opensource/libyang/src/tree_data_common.c:469
#5  0x00007ffff6e09b39 in lyd_parse_opaq_list_error (node=0x5555557d7210, snode=0x7ffff06af960)
    at /data/lcx/opensource/libyang/src/tree_data_common.c:737
#6  0x00007ffff6e0a14d in lyd_parse_opaq_error (node=0x5555557d7210) at /data/lcx/opensource/libyang/src/tree_data_common.c:829

the info of node in frame 6

$2 = {
  {
    node = {
      hash = 0,
      flags = 0,
      schema = 0x0,
      parent = 0x5555557b56a0,
      next = 0x0,
      prev = 0x5555557d7210,
      meta = 0x0,
      priv = 0x0
    },
    {
      hash = 0,
      flags = 0,
      schema = 0x0,
      parent = 0x5555557b56a0,
      next = 0x0,
      prev = 0x5555557d7210,
      meta = 0x0,
      priv = 0x0
    }
  },
  child = 0x5555557c5050,
  name = {
    name = 0x7ffff0031340 "unicast",
    prefix = 0x0,
    {
      module_ns = 0x7ffff037d670 "urn:ntp",
      module_name = 0x7ffff037d670 "urn:ntp"
    }
  },
  value = 0x7ffff0015570 "",
  hints = 64,
  format = LY_VALUE_XML,
  val_prefix_data = 0x0,
  attr = 0x0,
  ctx = 0x7ffff0019760
}
@michalvasko
Copy link
Member

Could you please provide the steps for reproducing this? I may be able to fix this somehow even without it but would have no way of knowing if correctly.

@michalvasko michalvasko added the is:bug Bug description. label Aug 8, 2023
@lyzliyuzhi91
Copy link
Author

module:

module test {
  yang-version 1.1;
  namespace "urn:test";
  prefix t;

  container con {
    list lis {
      key "ke";
  leaf ke {
    type union {
      type int16 {
        range "1..600";
      }
      type string {
        length "2..8";
      }
    }
  }
}

rpc message:

<rpc message-id='63950' xmlns='urn:ietf:params:xml:ns:netconf:base:1.0'>
<get xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"><filter type="subtree"><con xmlns="urn:test"><lis><ke/></lis></con></filter></get>
</rpc>

snippet code concerned:

static int _check_opaq(ly_ctx_t *ly_ctx, const struct lyd_node *data, bool is_configuration)
{
    for (const struct lyd_node *iter = data; iter != NULL; iter = iter->next) {
        if (iter->schema != NULL) {
            if ((iter->schema->nodetype & LYD_NODE_INNER) != 0) {
                const struct lyd_node_inner *inner = (const struct lyd_node_inner *)iter;
                if (_check_opaq(ly_ctx, inner->child, is_configuration) != 0) {
                    return -1;
                }
            }
            continue;   
        }

        struct lyd_node_opaq *opaq = (struct lyd_node_opaq *)iter; 
        LY_ERR err = lyd_parse_opaq_error(iter);  // it will coredump here for the list node
        if (err != LY_EVALID) {     
            return -1;
        }
    }
    return 0;
}
LY_ERR err = lyd_parse_data_mem(ly_ctx, "<con xmlns="urn:test"><lis><ke/></lis></con>", LYD_XML, 0xd0000, 0x2, &ly_data);
...
int rc = _check_opaq(ly_ctx, ly_data, true)

thanks

@michalvasko
Copy link
Member

Okay, fixed in the latest devel branch.

@michalvasko michalvasko added the status:completed From the developer perspective, the issue was solved (bug fixed, question answered,...) label Aug 9, 2023
@lyzliyuzhi91
Copy link
Author

ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
is:bug Bug description. status:completed From the developer perspective, the issue was solved (bug fixed, question answered,...)
Projects
None yet
Development

No branches or pull requests

2 participants