YANG printer BUGFIX infinite loop and NULL-pointer access when printing compiled range
diff --git a/src/printer_yang.c b/src/printer_yang.c
index c042707..f002b32 100755
--- a/src/printer_yang.c
+++ b/src/printer_yang.c
@@ -480,7 +480,7 @@
static void
yprc_iffeatures(struct ypr_ctx *ctx, struct lysc_iffeature *iff, struct lysc_ext_instance *exts, int *flag)
{
- unsigned int u;
+ unsigned int u, v;
int extflag;
LY_ARRAY_FOR(iff, u) {
@@ -495,11 +495,11 @@
/* extensions */
LEVEL++;
- LY_ARRAY_FOR(exts, u) {
- if (exts[u].insubstmt != LYEXT_SUBSTMT_IFFEATURE || exts[u].insubstmt_index != u) {
+ LY_ARRAY_FOR(exts, v) {
+ if (exts[v].insubstmt != LYEXT_SUBSTMT_IFFEATURE || exts[v].insubstmt_index != u) {
continue;
}
- yprc_extension_instances(ctx, LYEXT_SUBSTMT_IFFEATURE, u, &exts[u], &extflag, 1);
+ yprc_extension_instances(ctx, LYEXT_SUBSTMT_IFFEATURE, u, &exts[v], &extflag, 1);
}
LEVEL--;
ypr_close(ctx, extflag);
@@ -701,8 +701,12 @@
int inner_flag = 0;
unsigned int u;
+ if (!range) {
+ return;
+ }
+
ypr_open(ctx->out, flag);
- ly_print(ctx->out, "%*s%s \"", (basetype == LY_TYPE_STRING || basetype == LY_TYPE_BINARY)? "length" : "range", INDENT);
+ ly_print(ctx->out, "%*s%s \"", INDENT, (basetype == LY_TYPE_STRING || basetype == LY_TYPE_BINARY) ? "length" : "range");
LY_ARRAY_FOR(range->parts, u) {
if (u > 0) {
ly_print(ctx->out, " | ");