Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tree data BUGFIX don't send null argument into strncmp #2289

Merged
merged 1 commit into from
Aug 19, 2024

Conversation

peckato1
Copy link
Contributor

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

Copy link
Member

@michalvasko michalvasko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second if already includes the check (not sure how missed the other) so please remove it and put it at the beginning in the first to be unified, thanks.

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
      CESNET#1 0x79c7f43faf24 in lyd_new_path_ /build/libyang/src/tree_data_new.c:1736:55
      CESNET#2 0x79c7f43fdf61 in lyd_new_path2 /build/libyang/src/tree_data_new.c:1861:12
      CESNET#3 0x79c7f5249b24 in sr_lyd_new_path /build/dependencies/sysrepo/src/ly_wrap.c:644:9
      CESNET#4 0x79c7f52ec883 in sr_edit_add /build/dependencies/sysrepo/src/edit_diff.c:3765:20
      CESNET#5 0x79c7f5195824 in sr_delete_item /build/dependencies/sysrepo/src/sysrepo.c:3453:16
      CESNET#6 0x5c9e51a98f6e in clear_test /build/sysrepo/tests/test_edit.c:120:5
      CESNET#7 0x79c7f56da98c  (/usr/lib/libcmocka.so.0+0x698c) (BuildId: 4d284c2a057f6dbeaa60a5e68cb5891237d21ae1)
      CESNET#8 0x79c7f56db51c in _cmocka_run_group_tests (/usr/lib/libcmocka.so.0+0x751c) (BuildId: 4d284c2a057f6dbeaa60a5e68cb5891237d21ae1)
      CESNET#9 0x5c9e51a91f41 in main /build/sysrepo/tests/test_edit.c:1571:12
      CESNET#10 0x79c7f3b4ec87  (/usr/lib/libc.so.6+0x25c87) (BuildId: 32a656aa5562eece8c59a585f5eacd6cf5e2307b)
      CESNET#11 0x79c7f3b4ed4b in __libc_start_main (/usr/lib/libc.so.6+0x25d4b) (BuildId: 32a656aa5562eece8c59a585f5eacd6cf5e2307b)
      CESNET#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
@peckato1
Copy link
Contributor Author

Oh, sorry, I copy-pasted and did not read the line properly. Thanks for catching it!

@michalvasko michalvasko merged commit f347169 into CESNET:devel Aug 19, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants