Skip to content

test/test_ipaddr: fix uninitialized ifaddrs/sockaddr fields - #72142

Open
Doracly wants to merge 1 commit into
ceph:mainfrom
Doracly:uninitialized_in_test_ipaddr
Open

Doracly wants to merge 1 commit into
ceph:mainfrom
Doracly:uninitialized_in_test_ipaddr

Conversation

@Doracly

@Doracly Doracly commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Several tests in unittest_ipaddr build ifaddrs and sockaddr_in{,6} structs on the stack without initializing all of their fields. The tests pass, but valgrind reports the code under test branching on uninitialized values:

  • grade_addr() checks ifa_flags & IFF_UP for every candidate in find_ip_in_subnet_list() (pick_address.find_ip_in_subnet_list, pick_address.filtering)
  • getnameinfo() reads sin6_scope_id when pick_addresses() formats IPv6 candidates (pick_address.filtering)

The results only come out right because each query happens to match a single interface.

Fix

Initialize these structs with {}, including net in place of its memset. In the SkipLoopback tests, set ifa_flags = 0 instead of clearing IFF_UP from an indeterminate value.

Testing

valgrind --track-origins=yes bin/unittest_ipaddr
tests valgrind
before 47/47 pass 96 errors from 13 contexts
after 47/47 pass 0 errors

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

@github-actions

Copy link
Copy Markdown

Thank you for your contribution. Since you are not yet a member of the Ceph organization with write permissions on ceph/ceph.git, our CI will not automatically run. Any member of the Ceph organization may label this PR ci-approved to allow Jenkins CI jobs to run.

@Doracly

Doracly commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

jenkins test make check

@Doracly

Doracly commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

jenkins test make check arm64

@Doracly

Doracly commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

@NitzanMordhai could you review this? #73603 and #73608 (closed in favour of this one) fix the same uninitialized ifaddrs/sockaddr reads in test_ipaddr.

@NitzanMordhai NitzanMordhai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor: consider squashing the two commits. The first one's title covers the sockaddr locals but skips net, and the second just finishes that.

Other than that LGTM, thanks!

Several tests left fields of stack-allocated ifaddrs and
sockaddr_in{,6} structs uninitialized. Valgrind reports the code under
test branching on them:

- grade_addr() checks ifa_flags & IFF_UP
- getnameinfo() reads sin6_scope_id

Initialize these structs with {}, including net in place of its
memset. In the SkipLoopback tests, set ifa_flags = 0 instead of
clearing IFF_UP from an indeterminate value.

Assisted-by: claude-opus-5-5
Signed-off-by: Dominik Raddatz <[email protected]>
@Doracly
Doracly force-pushed the uninitialized_in_test_ipaddr branch from 9893634 to d63e1a5 Compare November 11, 2026 09:54
@Doracly

Doracly commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

Minor: consider squashing the two commits. The first one's title covers the sockaddr locals but skips net, and the second just finishes that.

Other than that LGTM, thanks!

Squashed, thanks!

@Doracly

Doracly commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

jenkins test windows

@SrinivasaBharath

Copy link
Copy Markdown
Contributor

This PR has been added to wip-bharath1-testing-20261114.051618-main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants