Skip to content

Commit ddb7e99

Browse files
choppsv1rjarry
authored andcommitted
context: fix libyang abort/crash on parse_data validation error
This crash (abort) is hit when the parsed data does not validate: python3: ..validation.c:1998: lyd_validate: Assertion `tree && ctx' failed. Aborted The `tree` mentioned in the assert is from last value ffi.NULL that was passed in in the `parent is not None` case. Instead just pass a pointer for a return value regardless of the parent value. Signed-off-by: Christian Hopps <[email protected]>
1 parent 2cae616 commit ddb7e99

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

libyang/context.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -615,24 +615,10 @@ def parse_data(
615615
if ret != lib.LY_SUCCESS:
616616
raise self.error("failed to read input data")
617617

618-
if parent is not None:
619-
ret = lib.lyd_parse_data(
620-
self.cdata,
621-
parent.cdata,
622-
data[0],
623-
fmt,
624-
parser_flgs,
625-
validation_flgs,
626-
ffi.NULL,
627-
)
628-
lib.ly_in_free(data[0], 0)
629-
if ret != lib.LY_SUCCESS:
630-
raise self.error("failed to parse data tree")
631-
return None
632-
618+
parent_cdata = parent.cdata if parent is not None else ffi.NULL
633619
dnode = ffi.new("struct lyd_node **")
634620
ret = lib.lyd_parse_data(
635-
self.cdata, ffi.NULL, data[0], fmt, parser_flgs, validation_flgs, dnode
621+
self.cdata, parent_cdata, data[0], fmt, parser_flgs, validation_flgs, dnode
636622
)
637623
lib.ly_in_free(data[0], 0)
638624
if ret != lib.LY_SUCCESS:

0 commit comments

Comments
 (0)