Skip to content

Commit 9a4e5b2

Browse files
committed
Merge branch 'devel'
2 parents d57c888 + 892355e commit 9a4e5b2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+3338
-2098
lines changed

.github/workflows/codeql.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ on:
55
branches: [ "master", "devel" ]
66
pull_request:
77
branches: [ "devel" ]
8-
schedule:
9-
- cron: "38 17 * * 4"
108

119
jobs:
1210
analyze:

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
6161
# set version of the project
6262
set(LIBYANG_MAJOR_VERSION 2)
6363
set(LIBYANG_MINOR_VERSION 1)
64-
set(LIBYANG_MICRO_VERSION 30)
64+
set(LIBYANG_MICRO_VERSION 55)
6565
set(LIBYANG_VERSION ${LIBYANG_MAJOR_VERSION}.${LIBYANG_MINOR_VERSION}.${LIBYANG_MICRO_VERSION})
6666
# set version of the library
6767
set(LIBYANG_MAJOR_SOVERSION 2)
68-
set(LIBYANG_MINOR_SOVERSION 29)
69-
set(LIBYANG_MICRO_SOVERSION 2)
68+
set(LIBYANG_MINOR_SOVERSION 33)
69+
set(LIBYANG_MICRO_SOVERSION 3)
7070
set(LIBYANG_SOVERSION_FULL ${LIBYANG_MAJOR_SOVERSION}.${LIBYANG_MINOR_SOVERSION}.${LIBYANG_MICRO_SOVERSION})
7171
set(LIBYANG_SOVERSION ${LIBYANG_MAJOR_SOVERSION})
7272

CMakeModules/UseCompat.cmake

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ macro(USE_COMPAT)
2727
set(CMAKE_REQUIRED_DEFINITIONS -D_POSIX_C_SOURCE=200809L)
2828
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
2929
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D__BSD_VISIBLE=1)
30+
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_DEFAULT_SOURCE)
3031
set(CMAKE_REQUIRED_LIBRARIES pthread)
3132

3233
check_symbol_exists(vdprintf "stdio.h;stdarg.h" HAVE_VDPRINTF)
@@ -47,13 +48,10 @@ macro(USE_COMPAT)
4748

4849
check_include_file("stdatomic.h" HAVE_STDATOMIC)
4950

50-
include(CheckStructHasMember)
51-
check_struct_has_member("struct tm" tm_gmtoff time.h HAVE_TM_GMTOFF)
52-
check_symbol_exists(timezone time.h HAVE_TIME_H_TIMEZONE)
53-
5451
check_symbol_exists(realpath "stdlib.h" HAVE_REALPATH)
5552
check_symbol_exists(localtime_r "time.h" HAVE_LOCALTIME_R)
5653
check_symbol_exists(gmtime_r "time.h" HAVE_GMTIME_R)
54+
check_function_exists(timegm HAVE_TIMEGM)
5755
check_symbol_exists(strptime "time.h" HAVE_STRPTIME)
5856
check_symbol_exists(mmap "sys/mman.h" HAVE_MMAP)
5957
check_symbol_exists(dirname "libgen.h" HAVE_DIRNAME)

compat/compat.h.in

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @author Michal Vasko <[email protected]>
44
* @brief compatibility functions header
55
*
6-
* Copyright (c) 2021 CESNET, z.s.p.o.
6+
* Copyright (c) 2021 - 2023 CESNET, z.s.p.o.
77
*
88
* This source code is licensed under BSD 3-Clause License (the "License").
99
* You may not use this file except in compliance with the License.
@@ -65,11 +65,10 @@
6565
#cmakedefine HAVE_STRCHRNUL
6666
#cmakedefine HAVE_GET_CURRENT_DIR_NAME
6767
#cmakedefine HAVE_PTHREAD_MUTEX_TIMEDLOCK
68-
#cmakedefine HAVE_TM_GMTOFF
69-
#cmakedefine HAVE_TIME_H_TIMEZONE
7068
#cmakedefine HAVE_REALPATH
7169
#cmakedefine HAVE_LOCALTIME_R
7270
#cmakedefine HAVE_GMTIME_R
71+
#cmakedefine HAVE_TIMEGM
7372
#cmakedefine HAVE_STRPTIME
7473
#cmakedefine HAVE_MMAP
7574
#cmakedefine HAVE_DIRNAME
@@ -188,6 +187,18 @@ char *realpath(const char *path, char *resolved_path);
188187
struct tm *localtime_r(const time_t *timep, struct tm *result);
189188
#endif
190189

190+
#ifndef HAVE_GMTIME_R
191+
struct tm *gmtime_r(const time_t *timep, struct tm *result);
192+
#endif
193+
194+
#ifndef HAVE_TIMEGM
195+
# if defined (_WIN32)
196+
# define timegm _mkgmtime
197+
# else
198+
# error No timegm() implementation for this platform is available.
199+
# endif
200+
#endif
201+
191202
#ifndef HAVE_STRPTIME
192203
char *strptime(const char *s, const char *format, struct tm *tm);
193204
#endif

src/common.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ struct lysc_node;
5656
* Logger
5757
*****************************************************************************/
5858

59+
/** size of the last message buffer */
60+
#define LY_LAST_MSG_SIZE 512
61+
5962
extern ATOMIC_T ly_ll;
6063
extern ATOMIC_T ly_log_opts;
6164

@@ -87,6 +90,14 @@ void ly_log(const struct ly_ctx *ctx, LY_LOG_LEVEL level, LY_ERR no, const char
8790
*/
8891
void ly_vlog(const struct ly_ctx *ctx, const char *apptag, LY_VECODE code, const char *format, ...);
8992

93+
/**
94+
* @brief Move error items from source to target context replacing any previous ones.
95+
*
96+
* @param[in] src_ctx Source context to read errors from.
97+
* @param[in] trg_ctx Target context to set the errors for.
98+
*/
99+
void ly_err_move(struct ly_ctx *src_ctx, struct ly_ctx *trg_ctx);
100+
90101
/**
91102
* @brief Logger's location data setter.
92103
*

src/diff.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,13 @@ lyd_diff_add(const struct lyd_node *node, enum lyd_diff_op op, const char *orig_
213213
}
214214

215215
/* duplicate the subtree (and connect to the diff if possible) */
216-
LY_CHECK_RET(lyd_dup_single(node, (struct lyd_node_inner *)diff_parent,
217-
LYD_DUP_RECURSIVE | LYD_DUP_NO_META | LYD_DUP_WITH_PARENTS | LYD_DUP_WITH_FLAGS, &dup));
216+
if (diff_parent) {
217+
LY_CHECK_RET(lyd_dup_single_to_ctx(node, LYD_CTX(diff_parent), (struct lyd_node_inner *)diff_parent,
218+
LYD_DUP_RECURSIVE | LYD_DUP_NO_META | LYD_DUP_WITH_PARENTS | LYD_DUP_WITH_FLAGS, &dup));
219+
} else {
220+
LY_CHECK_RET(lyd_dup_single(node, NULL,
221+
LYD_DUP_RECURSIVE | LYD_DUP_NO_META | LYD_DUP_WITH_PARENTS | LYD_DUP_WITH_FLAGS, &dup));
222+
}
218223

219224
/* find the first duplicated parent */
220225
if (!diff_parent) {
@@ -648,13 +653,13 @@ lyd_diff_attrs(const struct lyd_node *first, const struct lyd_node *second, uint
648653
* @param[in] siblings Siblings to search in.
649654
* @param[in] target Target node to search for.
650655
* @param[in] defaults Whether to consider (or ignore) default values.
651-
* @param[in,out] dup_inst_cache Duplicate instance cache.
656+
* @param[in,out] dup_inst_ht Duplicate instance cache.
652657
* @param[out] match Found match, NULL if no matching node found.
653658
* @return LY_ERR value.
654659
*/
655660
static LY_ERR
656661
lyd_diff_find_match(const struct lyd_node *siblings, const struct lyd_node *target, ly_bool defaults,
657-
struct lyd_dup_inst **dup_inst_cache, struct lyd_node **match)
662+
struct hash_table **dup_inst_ht, struct lyd_node **match)
658663
{
659664
LY_ERR r;
660665

@@ -670,7 +675,7 @@ lyd_diff_find_match(const struct lyd_node *siblings, const struct lyd_node *targ
670675
}
671676

672677
/* update match as needed */
673-
LY_CHECK_RET(lyd_dup_inst_next(match, siblings, dup_inst_cache));
678+
LY_CHECK_RET(lyd_dup_inst_next(match, siblings, dup_inst_ht));
674679

675680
if (*match && ((*match)->flags & LYD_DEFAULT) && !defaults) {
676681
/* ignore default nodes */
@@ -728,7 +733,7 @@ lyd_diff_siblings_r(const struct lyd_node *first, const struct lyd_node *second,
728733
const struct lyd_node *iter_first, *iter_second;
729734
struct lyd_node *match_second, *match_first;
730735
struct lyd_diff_userord *userord = NULL, *userord_item;
731-
struct lyd_dup_inst *dup_inst_first = NULL, *dup_inst_second = NULL;
736+
struct hash_table *dup_inst_first = NULL, *dup_inst_second = NULL;
732737
LY_ARRAY_COUNT_TYPE u;
733738
enum lyd_diff_op op;
734739
const char *orig_default;
@@ -1079,14 +1084,14 @@ lyd_diff_insert(struct lyd_node **first_node, struct lyd_node *parent_node, stru
10791084
*/
10801085
static LY_ERR
10811086
lyd_diff_apply_r(struct lyd_node **first_node, struct lyd_node *parent_node, const struct lyd_node *diff_node,
1082-
lyd_diff_cb diff_cb, void *cb_data, struct lyd_dup_inst **dup_inst)
1087+
lyd_diff_cb diff_cb, void *cb_data, struct hash_table **dup_inst)
10831088
{
10841089
LY_ERR ret;
10851090
struct lyd_node *match, *diff_child;
10861091
const char *str_val, *meta_str;
10871092
enum lyd_diff_op op;
10881093
struct lyd_meta *meta;
1089-
struct lyd_dup_inst *child_dup_inst = NULL;
1094+
struct hash_table *child_dup_inst = NULL;
10901095
const struct ly_ctx *ctx = LYD_CTX(diff_node);
10911096

10921097
/* read all the valid attributes */
@@ -1242,7 +1247,7 @@ lyd_diff_apply_module(struct lyd_node **data, const struct lyd_node *diff, const
12421247
lyd_diff_cb diff_cb, void *cb_data)
12431248
{
12441249
const struct lyd_node *root;
1245-
struct lyd_dup_inst *dup_inst = NULL;
1250+
struct hash_table *dup_inst = NULL;
12461251
LY_ERR ret = LY_SUCCESS;
12471252

12481253
LY_LIST_FOR(diff, root) {
@@ -1757,12 +1762,12 @@ lyd_diff_is_redundant(struct lyd_node *diff)
17571762
*/
17581763
static LY_ERR
17591764
lyd_diff_merge_r(const struct lyd_node *src_diff, struct lyd_node *diff_parent, lyd_diff_cb diff_cb, void *cb_data,
1760-
struct lyd_dup_inst **dup_inst, uint16_t options, struct lyd_node **diff)
1765+
struct hash_table **dup_inst, uint16_t options, struct lyd_node **diff)
17611766
{
17621767
LY_ERR ret = LY_SUCCESS;
17631768
struct lyd_node *child, *diff_node = NULL;
17641769
enum lyd_diff_op src_op, cur_op;
1765-
struct lyd_dup_inst *child_dup_inst = NULL;
1770+
struct hash_table *child_dup_inst = NULL;
17661771

17671772
/* get source node operation */
17681773
LY_CHECK_RET(lyd_diff_get_op(src_diff, &src_op));
@@ -1868,7 +1873,7 @@ lyd_diff_merge_module(struct lyd_node **diff, const struct lyd_node *src_diff, c
18681873
lyd_diff_cb diff_cb, void *cb_data, uint16_t options)
18691874
{
18701875
const struct lyd_node *src_root;
1871-
struct lyd_dup_inst *dup_inst = NULL;
1876+
struct hash_table *dup_inst = NULL;
18721877
LY_ERR ret = LY_SUCCESS;
18731878

18741879
LY_LIST_FOR(src_diff, src_root) {
@@ -1891,7 +1896,7 @@ lyd_diff_merge_tree(struct lyd_node **diff_first, struct lyd_node *diff_parent,
18911896
lyd_diff_cb diff_cb, void *cb_data, uint16_t options)
18921897
{
18931898
LY_ERR ret;
1894-
struct lyd_dup_inst *dup_inst = NULL;
1899+
struct hash_table *dup_inst = NULL;
18951900

18961901
if (!src_sibling) {
18971902
return LY_SUCCESS;

src/hash_table.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ lydict_clean(struct dict_table *dict)
8787
}
8888

8989
/* free table and destroy mutex */
90-
lyht_free(dict->hash_tab);
90+
lyht_free(dict->hash_tab, NULL);
9191
pthread_mutex_destroy(&dict->lock);
9292
}
9393

@@ -381,12 +381,25 @@ lyht_dup(const struct hash_table *orig)
381381
}
382382

383383
void
384-
lyht_free(struct hash_table *ht)
384+
lyht_free(struct hash_table *ht, void (*val_free)(void *val_p))
385385
{
386-
if (ht) {
387-
free(ht->recs);
388-
free(ht);
386+
struct ht_rec *rec;
387+
uint32_t i;
388+
389+
if (!ht) {
390+
return;
391+
}
392+
393+
if (val_free) {
394+
for (i = 0; i < ht->size; ++i) {
395+
rec = lyht_get_rec(ht->recs, ht->rec_size, i);
396+
if (rec->hits > 0) {
397+
val_free(&rec->val);
398+
}
399+
}
389400
}
401+
free(ht->recs);
402+
free(ht);
390403
}
391404

392405
/**

src/hash_table.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,9 @@ struct hash_table *lyht_dup(const struct hash_table *orig);
167167
* @brief Free a hash table.
168168
*
169169
* @param[in] ht Hash table to be freed.
170+
* @param[in] val_free Optional callback for freeing allthe stored values, @p val_p is a pointer to a stored value.
170171
*/
171-
void lyht_free(struct hash_table *ht);
172+
void lyht_free(struct hash_table *ht, void (*val_free)(void *val_p));
172173

173174
/**
174175
* @brief Find a value in a hash table.

src/json.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -830,11 +830,7 @@ lyjson_value(struct lyjson_ctx *jsonctx)
830830

831831
} else if (*jsonctx->in->current == '{') {
832832
jsonctx->depth++;
833-
if (jsonctx->depth > LY_MAX_BLOCK_DEPTH) {
834-
LOGERR(jsonctx->ctx, LY_EINVAL,
835-
"The maximum number of block nestings has been exceeded.");
836-
return LY_EINVAL;
837-
}
833+
838834
/* object */
839835
ly_in_skip(jsonctx->in, 1);
840836
LY_CHECK_RET(lyjson_object(jsonctx));
@@ -850,6 +846,14 @@ lyjson_value(struct lyjson_ctx *jsonctx)
850846
return LY_EVALID;
851847
}
852848

849+
if (jsonctx->depth > LY_MAX_BLOCK_DEPTH) {
850+
LOGERR(jsonctx->ctx, LY_EINVAL, "Maximum number %d of block nestings has been exceeded.", LY_MAX_BLOCK_DEPTH);
851+
return LY_EINVAL;
852+
} else if (jsonctx->status.count > LY_MAX_BLOCK_DEPTH * 10) {
853+
LOGERR(jsonctx->ctx, LY_EINVAL, "Maximum number %d of nestings has been exceeded.", LY_MAX_BLOCK_DEPTH * 10);
854+
return LY_EINVAL;
855+
}
856+
853857
return LY_SUCCESS;
854858
}
855859

0 commit comments

Comments
 (0)