Skip to content

Commit

Permalink
tree data BUGFIX don't send null argument into strncmp
Browse files Browse the repository at this point in the history
The recent patch was sending a NULL pointer to ly_strncmp which passed
the NULL to strncmp. However, strncmp arguments are attributed as
nonnull which make undefined behaviour sanitizer unhappy.

This ubsan report appeared when running sysrepo tests:

  /build/libyang/src/ly_common.c:114:30: runtime error: null pointer passed as argument 2, which is declared to never be null
  /usr/include/string.h:160:33: note: nonnull attribute specified here
      #0 0x79c7f4278907 in ly_strncmp /build/libyang/src/ly_common.c:114:14
      #1 0x79c7f43faf24 in lyd_new_path_ /build/libyang/src/tree_data_new.c:1736:55
      #2 0x79c7f43fdf61 in lyd_new_path2 /build/libyang/src/tree_data_new.c:1861:12
      #3 0x79c7f5249b24 in sr_lyd_new_path /build/dependencies/sysrepo/src/ly_wrap.c:644:9
      #4 0x79c7f52ec883 in sr_edit_add /build/dependencies/sysrepo/src/edit_diff.c:3765:20
      #5 0x79c7f5195824 in sr_delete_item /build/dependencies/sysrepo/src/sysrepo.c:3453:16
      #6 0x5c9e51a98f6e in clear_test /build/sysrepo/tests/test_edit.c:120:5
      #7 0x79c7f56da98c  (/usr/lib/libcmocka.so.0+0x698c) (BuildId: 4d284c2a057f6dbeaa60a5e68cb5891237d21ae1)
      #8 0x79c7f56db51c in _cmocka_run_group_tests (/usr/lib/libcmocka.so.0+0x751c) (BuildId: 4d284c2a057f6dbeaa60a5e68cb5891237d21ae1)
      #9 0x5c9e51a91f41 in main /build/sysrepo/tests/test_edit.c:1571:12
      #10 0x79c7f3b4ec87  (/usr/lib/libc.so.6+0x25c87) (BuildId: 32a656aa5562eece8c59a585f5eacd6cf5e2307b)
      #11 0x79c7f3b4ed4b in __libc_start_main (/usr/lib/libc.so.6+0x25d4b) (BuildId: 32a656aa5562eece8c59a585f5eacd6cf5e2307b)
      #12 0x5c9e5195a2b4 in _start (/build/sysrepo/build-clang-asan/tests/test_edit+0x3a2b4) (BuildId: dc378717130c22094495ee54dcfbdc3254b5f981)

Fixes: ed74a24 tree data UPDATE recognize special JSON [null] value
  • Loading branch information
peckato1 authored and michalvasko committed Aug 19, 2024
1 parent 747486a commit f347169
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/tree_data_new.c
Original file line number Diff line number Diff line change
Expand Up @@ -1733,7 +1733,7 @@ lyd_new_path_(struct lyd_node *parent, const struct ly_ctx *ctx, const struct ly
if (r && (r != LY_EINCOMPLETE)) {
/* creating opaque leaf-list */
hints = LYD_NODEHINT_LEAFLIST;
if ((format == LY_VALUE_JSON) && !ly_strncmp("[null]", value, value_len)) {
if (value && (format == LY_VALUE_JSON) && !ly_strncmp("[null]", value, value_len)) {
hints |= LYD_VALHINT_EMPTY;
}
LY_CHECK_GOTO(ret = lyd_create_opaq(ctx, schema->name, strlen(schema->name), NULL, 0,
Expand Down

0 comments on commit f347169

Please sign in to comment.