Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
michalvasko committed Mar 17, 2023
2 parents d57c888 + 892355e commit 9a4e5b2
Show file tree
Hide file tree
Showing 81 changed files with 3,338 additions and 2,098 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ on:
branches: [ "master", "devel" ]
pull_request:
branches: [ "devel" ]
schedule:
- cron: "38 17 * * 4"

jobs:
analyze:
Expand Down
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
# set version of the project
set(LIBYANG_MAJOR_VERSION 2)
set(LIBYANG_MINOR_VERSION 1)
set(LIBYANG_MICRO_VERSION 30)
set(LIBYANG_MICRO_VERSION 55)
set(LIBYANG_VERSION ${LIBYANG_MAJOR_VERSION}.${LIBYANG_MINOR_VERSION}.${LIBYANG_MICRO_VERSION})
# set version of the library
set(LIBYANG_MAJOR_SOVERSION 2)
set(LIBYANG_MINOR_SOVERSION 29)
set(LIBYANG_MICRO_SOVERSION 2)
set(LIBYANG_MINOR_SOVERSION 33)
set(LIBYANG_MICRO_SOVERSION 3)
set(LIBYANG_SOVERSION_FULL ${LIBYANG_MAJOR_SOVERSION}.${LIBYANG_MINOR_SOVERSION}.${LIBYANG_MICRO_SOVERSION})
set(LIBYANG_SOVERSION ${LIBYANG_MAJOR_SOVERSION})

Expand Down
6 changes: 2 additions & 4 deletions CMakeModules/UseCompat.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ macro(USE_COMPAT)
set(CMAKE_REQUIRED_DEFINITIONS -D_POSIX_C_SOURCE=200809L)
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D__BSD_VISIBLE=1)
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_DEFAULT_SOURCE)
set(CMAKE_REQUIRED_LIBRARIES pthread)

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

check_include_file("stdatomic.h" HAVE_STDATOMIC)

include(CheckStructHasMember)
check_struct_has_member("struct tm" tm_gmtoff time.h HAVE_TM_GMTOFF)
check_symbol_exists(timezone time.h HAVE_TIME_H_TIMEZONE)

check_symbol_exists(realpath "stdlib.h" HAVE_REALPATH)
check_symbol_exists(localtime_r "time.h" HAVE_LOCALTIME_R)
check_symbol_exists(gmtime_r "time.h" HAVE_GMTIME_R)
check_function_exists(timegm HAVE_TIMEGM)
check_symbol_exists(strptime "time.h" HAVE_STRPTIME)
check_symbol_exists(mmap "sys/mman.h" HAVE_MMAP)
check_symbol_exists(dirname "libgen.h" HAVE_DIRNAME)
Expand Down
17 changes: 14 additions & 3 deletions compat/compat.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @author Michal Vasko <[email protected]>
* @brief compatibility functions header
*
* Copyright (c) 2021 CESNET, z.s.p.o.
* Copyright (c) 2021 - 2023 CESNET, z.s.p.o.
*
* This source code is licensed under BSD 3-Clause License (the "License").
* You may not use this file except in compliance with the License.
Expand Down Expand Up @@ -65,11 +65,10 @@
#cmakedefine HAVE_STRCHRNUL
#cmakedefine HAVE_GET_CURRENT_DIR_NAME
#cmakedefine HAVE_PTHREAD_MUTEX_TIMEDLOCK
#cmakedefine HAVE_TM_GMTOFF
#cmakedefine HAVE_TIME_H_TIMEZONE
#cmakedefine HAVE_REALPATH
#cmakedefine HAVE_LOCALTIME_R
#cmakedefine HAVE_GMTIME_R
#cmakedefine HAVE_TIMEGM
#cmakedefine HAVE_STRPTIME
#cmakedefine HAVE_MMAP
#cmakedefine HAVE_DIRNAME
Expand Down Expand Up @@ -188,6 +187,18 @@ char *realpath(const char *path, char *resolved_path);
struct tm *localtime_r(const time_t *timep, struct tm *result);
#endif

#ifndef HAVE_GMTIME_R
struct tm *gmtime_r(const time_t *timep, struct tm *result);
#endif

#ifndef HAVE_TIMEGM
# if defined (_WIN32)
# define timegm _mkgmtime
# else
# error No timegm() implementation for this platform is available.
# endif
#endif

#ifndef HAVE_STRPTIME
char *strptime(const char *s, const char *format, struct tm *tm);
#endif
Expand Down
11 changes: 11 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ struct lysc_node;
* Logger
*****************************************************************************/

/** size of the last message buffer */
#define LY_LAST_MSG_SIZE 512

extern ATOMIC_T ly_ll;
extern ATOMIC_T ly_log_opts;

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

/**
* @brief Move error items from source to target context replacing any previous ones.
*
* @param[in] src_ctx Source context to read errors from.
* @param[in] trg_ctx Target context to set the errors for.
*/
void ly_err_move(struct ly_ctx *src_ctx, struct ly_ctx *trg_ctx);

/**
* @brief Logger's location data setter.
*
Expand Down
31 changes: 18 additions & 13 deletions src/diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,13 @@ lyd_diff_add(const struct lyd_node *node, enum lyd_diff_op op, const char *orig_
}

/* duplicate the subtree (and connect to the diff if possible) */
LY_CHECK_RET(lyd_dup_single(node, (struct lyd_node_inner *)diff_parent,
LYD_DUP_RECURSIVE | LYD_DUP_NO_META | LYD_DUP_WITH_PARENTS | LYD_DUP_WITH_FLAGS, &dup));
if (diff_parent) {
LY_CHECK_RET(lyd_dup_single_to_ctx(node, LYD_CTX(diff_parent), (struct lyd_node_inner *)diff_parent,
LYD_DUP_RECURSIVE | LYD_DUP_NO_META | LYD_DUP_WITH_PARENTS | LYD_DUP_WITH_FLAGS, &dup));
} else {
LY_CHECK_RET(lyd_dup_single(node, NULL,
LYD_DUP_RECURSIVE | LYD_DUP_NO_META | LYD_DUP_WITH_PARENTS | LYD_DUP_WITH_FLAGS, &dup));
}

/* find the first duplicated parent */
if (!diff_parent) {
Expand Down Expand Up @@ -648,13 +653,13 @@ lyd_diff_attrs(const struct lyd_node *first, const struct lyd_node *second, uint
* @param[in] siblings Siblings to search in.
* @param[in] target Target node to search for.
* @param[in] defaults Whether to consider (or ignore) default values.
* @param[in,out] dup_inst_cache Duplicate instance cache.
* @param[in,out] dup_inst_ht Duplicate instance cache.
* @param[out] match Found match, NULL if no matching node found.
* @return LY_ERR value.
*/
static LY_ERR
lyd_diff_find_match(const struct lyd_node *siblings, const struct lyd_node *target, ly_bool defaults,
struct lyd_dup_inst **dup_inst_cache, struct lyd_node **match)
struct hash_table **dup_inst_ht, struct lyd_node **match)
{
LY_ERR r;

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

/* update match as needed */
LY_CHECK_RET(lyd_dup_inst_next(match, siblings, dup_inst_cache));
LY_CHECK_RET(lyd_dup_inst_next(match, siblings, dup_inst_ht));

if (*match && ((*match)->flags & LYD_DEFAULT) && !defaults) {
/* ignore default nodes */
Expand Down Expand Up @@ -728,7 +733,7 @@ lyd_diff_siblings_r(const struct lyd_node *first, const struct lyd_node *second,
const struct lyd_node *iter_first, *iter_second;
struct lyd_node *match_second, *match_first;
struct lyd_diff_userord *userord = NULL, *userord_item;
struct lyd_dup_inst *dup_inst_first = NULL, *dup_inst_second = NULL;
struct hash_table *dup_inst_first = NULL, *dup_inst_second = NULL;
LY_ARRAY_COUNT_TYPE u;
enum lyd_diff_op op;
const char *orig_default;
Expand Down Expand Up @@ -1079,14 +1084,14 @@ lyd_diff_insert(struct lyd_node **first_node, struct lyd_node *parent_node, stru
*/
static LY_ERR
lyd_diff_apply_r(struct lyd_node **first_node, struct lyd_node *parent_node, const struct lyd_node *diff_node,
lyd_diff_cb diff_cb, void *cb_data, struct lyd_dup_inst **dup_inst)
lyd_diff_cb diff_cb, void *cb_data, struct hash_table **dup_inst)
{
LY_ERR ret;
struct lyd_node *match, *diff_child;
const char *str_val, *meta_str;
enum lyd_diff_op op;
struct lyd_meta *meta;
struct lyd_dup_inst *child_dup_inst = NULL;
struct hash_table *child_dup_inst = NULL;
const struct ly_ctx *ctx = LYD_CTX(diff_node);

/* read all the valid attributes */
Expand Down Expand Up @@ -1242,7 +1247,7 @@ lyd_diff_apply_module(struct lyd_node **data, const struct lyd_node *diff, const
lyd_diff_cb diff_cb, void *cb_data)
{
const struct lyd_node *root;
struct lyd_dup_inst *dup_inst = NULL;
struct hash_table *dup_inst = NULL;
LY_ERR ret = LY_SUCCESS;

LY_LIST_FOR(diff, root) {
Expand Down Expand Up @@ -1757,12 +1762,12 @@ lyd_diff_is_redundant(struct lyd_node *diff)
*/
static LY_ERR
lyd_diff_merge_r(const struct lyd_node *src_diff, struct lyd_node *diff_parent, lyd_diff_cb diff_cb, void *cb_data,
struct lyd_dup_inst **dup_inst, uint16_t options, struct lyd_node **diff)
struct hash_table **dup_inst, uint16_t options, struct lyd_node **diff)
{
LY_ERR ret = LY_SUCCESS;
struct lyd_node *child, *diff_node = NULL;
enum lyd_diff_op src_op, cur_op;
struct lyd_dup_inst *child_dup_inst = NULL;
struct hash_table *child_dup_inst = NULL;

/* get source node operation */
LY_CHECK_RET(lyd_diff_get_op(src_diff, &src_op));
Expand Down Expand Up @@ -1868,7 +1873,7 @@ lyd_diff_merge_module(struct lyd_node **diff, const struct lyd_node *src_diff, c
lyd_diff_cb diff_cb, void *cb_data, uint16_t options)
{
const struct lyd_node *src_root;
struct lyd_dup_inst *dup_inst = NULL;
struct hash_table *dup_inst = NULL;
LY_ERR ret = LY_SUCCESS;

LY_LIST_FOR(src_diff, src_root) {
Expand All @@ -1891,7 +1896,7 @@ lyd_diff_merge_tree(struct lyd_node **diff_first, struct lyd_node *diff_parent,
lyd_diff_cb diff_cb, void *cb_data, uint16_t options)
{
LY_ERR ret;
struct lyd_dup_inst *dup_inst = NULL;
struct hash_table *dup_inst = NULL;

if (!src_sibling) {
return LY_SUCCESS;
Expand Down
23 changes: 18 additions & 5 deletions src/hash_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ lydict_clean(struct dict_table *dict)
}

/* free table and destroy mutex */
lyht_free(dict->hash_tab);
lyht_free(dict->hash_tab, NULL);
pthread_mutex_destroy(&dict->lock);
}

Expand Down Expand Up @@ -381,12 +381,25 @@ lyht_dup(const struct hash_table *orig)
}

void
lyht_free(struct hash_table *ht)
lyht_free(struct hash_table *ht, void (*val_free)(void *val_p))
{
if (ht) {
free(ht->recs);
free(ht);
struct ht_rec *rec;
uint32_t i;

if (!ht) {
return;
}

if (val_free) {
for (i = 0; i < ht->size; ++i) {
rec = lyht_get_rec(ht->recs, ht->rec_size, i);
if (rec->hits > 0) {
val_free(&rec->val);
}
}
}
free(ht->recs);
free(ht);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/hash_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,9 @@ struct hash_table *lyht_dup(const struct hash_table *orig);
* @brief Free a hash table.
*
* @param[in] ht Hash table to be freed.
* @param[in] val_free Optional callback for freeing allthe stored values, @p val_p is a pointer to a stored value.
*/
void lyht_free(struct hash_table *ht);
void lyht_free(struct hash_table *ht, void (*val_free)(void *val_p));

/**
* @brief Find a value in a hash table.
Expand Down
14 changes: 9 additions & 5 deletions src/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -830,11 +830,7 @@ lyjson_value(struct lyjson_ctx *jsonctx)

} else if (*jsonctx->in->current == '{') {
jsonctx->depth++;
if (jsonctx->depth > LY_MAX_BLOCK_DEPTH) {
LOGERR(jsonctx->ctx, LY_EINVAL,
"The maximum number of block nestings has been exceeded.");
return LY_EINVAL;
}

/* object */
ly_in_skip(jsonctx->in, 1);
LY_CHECK_RET(lyjson_object(jsonctx));
Expand All @@ -850,6 +846,14 @@ lyjson_value(struct lyjson_ctx *jsonctx)
return LY_EVALID;
}

if (jsonctx->depth > LY_MAX_BLOCK_DEPTH) {
LOGERR(jsonctx->ctx, LY_EINVAL, "Maximum number %d of block nestings has been exceeded.", LY_MAX_BLOCK_DEPTH);
return LY_EINVAL;
} else if (jsonctx->status.count > LY_MAX_BLOCK_DEPTH * 10) {
LOGERR(jsonctx->ctx, LY_EINVAL, "Maximum number %d of nestings has been exceeded.", LY_MAX_BLOCK_DEPTH * 10);
return LY_EINVAL;
}

return LY_SUCCESS;
}

Expand Down
Loading

0 comments on commit 9a4e5b2

Please sign in to comment.