Skip to content

Commit a45a1ac

Browse files
committed
Merge branch 'devel'
2 parents a4f3e9a + d838835 commit a45a1ac

2 files changed

Lines changed: 26 additions & 13 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ set(CMAKE_MACOSX_RPATH TRUE)
1111
# set version
1212
set(LIBYANG_MAJOR_VERSION 0)
1313
set(LIBYANG_MINOR_VERSION 13)
14-
set(LIBYANG_MICRO_VERSION 59)
14+
set(LIBYANG_MICRO_VERSION 61)
1515
set(LIBYANG_VERSION ${LIBYANG_MAJOR_VERSION}.${LIBYANG_MINOR_VERSION}.${LIBYANG_MICRO_VERSION})
1616
set(LIBYANG_SOVERSION ${LIBYANG_MAJOR_VERSION}.${LIBYANG_MINOR_VERSION})
1717
configure_file(${PROJECT_SOURCE_DIR}/src/libyang.h.in ${PROJECT_SOURCE_DIR}/src/libyang.h)

src/log.c

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -453,11 +453,13 @@ ly_vlog_build_path_reverse(enum LY_VLOG_ELEM elem_type, const void *elem, char *
453453
}
454454

455455
if (((struct lys_node *)elem)->nodetype & (LYS_AUGMENT | LYS_GROUPING)) {
456+
LY_CHECK_ERR_RETURN((*index) < 1, LOGERR(LY_SUCCESS, "%s: path is too long."),);
456457
--(*index);
457458
path[*index] = ']';
458459

459460
name = ((struct lys_node *)elem)->name;
460461
len = strlen(name);
462+
LY_CHECK_ERR_RETURN((*index) < len, LOGERR(LY_SUCCESS, "%s: path is too long."),);
461463
(*index) -= len;
462464
memcpy(&path[*index], name, len);
463465

@@ -523,19 +525,24 @@ ly_vlog_build_path_reverse(enum LY_VLOG_ELEM elem_type, const void *elem, char *
523525
val_end = "']";
524526
}
525527

528+
len = strlen(((struct lyd_node_leaf_list *)diter)->value_str);
529+
LY_CHECK_ERR_RETURN((*index) < len + 2, LOGERR(LY_SUCCESS, "%s: path is too long."),);
526530
(*index) -= 2;
527531
memcpy(&path[(*index)], val_end, 2);
528-
len = strlen(((struct lyd_node_leaf_list *)diter)->value_str);
529532
(*index) -= len;
530533
memcpy(&path[(*index)], ((struct lyd_node_leaf_list *)diter)->value_str, len);
534+
535+
len = strlen(diter->schema->name);
536+
LY_CHECK_ERR_RETURN((*index) < len + 3, LOGERR(LY_SUCCESS, "%s: path is too long."),);
531537
(*index) -= 2;
532538
memcpy(&path[(*index)], val_start, 2);
533-
len = strlen(diter->schema->name);
534539
(*index) -= len;
535540
memcpy(&path[(*index)], diter->schema->name, len);
541+
536542
if (lyd_node_module(dlist) != lyd_node_module(diter)) {
537-
path[--(*index)] = ':';
538543
len = strlen(lyd_node_module(diter)->name);
544+
LY_CHECK_ERR_RETURN((*index) < len + 2, LOGERR(LY_SUCCESS, "%s: path is too long."),);
545+
path[--(*index)] = ':';
539546
(*index) -= len;
540547
memcpy(&path[(*index)], lyd_node_module(diter)->name, len);
541548
}
@@ -544,8 +551,6 @@ ly_vlog_build_path_reverse(enum LY_VLOG_ELEM elem_type, const void *elem, char *
544551
}
545552
} else {
546553
/* schema list without keys - use instance position */
547-
path[--(*index)] = ']';
548-
549554
i = j = lyd_list_pos(dlist);
550555
len = 1;
551556
while (j > 9) {
@@ -557,6 +562,8 @@ ly_vlog_build_path_reverse(enum LY_VLOG_ELEM elem_type, const void *elem, char *
557562
LY_CHECK_ERR_RETURN(!str, LOGMEM, );
558563
sprintf(str, "%d", i);
559564

565+
LY_CHECK_ERR_RETURN((*index) < len + 2, free(str); LOGERR(LY_SUCCESS, "%s: path is too long."),);
566+
path[--(*index)] = ']';
560567
(*index) -= len;
561568
strncpy(&path[(*index)], str, len);
562569

@@ -575,9 +582,10 @@ ly_vlog_build_path_reverse(enum LY_VLOG_ELEM elem_type, const void *elem, char *
575582
val_end = "']";
576583
}
577584

585+
len = strlen(((struct lyd_node_leaf_list *)elem)->value_str);
586+
LY_CHECK_ERR_RETURN((*index) < len + 6, LOGERR(LY_SUCCESS, "%s: path is too long."),);
578587
(*index) -= 2;
579588
memcpy(&path[(*index)], val_end, 2);
580-
len = strlen(((struct lyd_node_leaf_list *)elem)->value_str);
581589
(*index) -= len;
582590
memcpy(&path[(*index)], ((struct lyd_node_leaf_list *)elem)->value_str, len);
583591
(*index) -= 4;
@@ -588,10 +596,11 @@ ly_vlog_build_path_reverse(enum LY_VLOG_ELEM elem_type, const void *elem, char *
588596
break;
589597
case LY_VLOG_STR:
590598
len = strlen((const char *)elem) + 1;
591-
if (len > LY_BUF_SIZE) {
592-
len = LY_BUF_SIZE - 1;
599+
if ((*index) < len) {
600+
LOGERR(LY_SUCCESS, "%s: path is too long.")
601+
len = (*index);
593602
}
594-
(*index) = LY_BUF_SIZE - len;
603+
(*index) = (*index) - len;
595604
memcpy(&path[(*index)], (const char *)elem, len - 1);
596605
return;
597606
default:
@@ -601,19 +610,23 @@ ly_vlog_build_path_reverse(enum LY_VLOG_ELEM elem_type, const void *elem, char *
601610
}
602611
if (name) {
603612
len = strlen(name);
613+
LY_CHECK_ERR_RETURN((*index) < len, LOGERR(LY_SUCCESS, "%s: path is too long."),);
604614
(*index) -= len;
605615
memcpy(&path[*index], name, len);
606616
if (prefix) {
607-
path[--(*index)] = ':';
608617
len = strlen(prefix);
609-
(*index) = (*index) - len;
618+
LY_CHECK_ERR_RETURN((*index) < len + 1, LOGERR(LY_SUCCESS, "%s: path is too long."),);
619+
path[--(*index)] = ':';
620+
(*index) -= len;
610621
memcpy(&path[(*index)], prefix, len);
611622
}
612623
}
624+
LY_CHECK_ERR_RETURN((*index) < 1, LOGERR(LY_SUCCESS, "%s: path is too long."),);
613625
path[--(*index)] = '/';
614626
if (elem_type == LY_VLOG_LYS && !elem && sparent && sparent->nodetype == LYS_AUGMENT) {
615627
len = strlen(((struct lys_node_augment *)sparent)->target_name);
616-
(*index) = (*index) - len;
628+
LY_CHECK_ERR_RETURN((*index) < len, LOGERR(LY_SUCCESS, "%s: path is too long."),);
629+
(*index) -= len;
617630
memcpy(&path[(*index)], ((struct lys_node_augment *)sparent)->target_name, len);
618631
}
619632
}

0 commit comments

Comments
 (0)