Skip to content

test: fix uninitialised memory reads in unittest_ipaddr - #73608

Closed
abrahamperz wants to merge 1 commit into
ceph:mainfrom
abrahamperz:wip-test-ipaddr-uninit
Closed

abrahamperz wants to merge 1 commit into
ceph:mainfrom
abrahamperz:wip-test-ipaddr-uninit

Conversation

@abrahamperz

Copy link
Copy Markdown
Contributor

Running unittest_ipaddr under valgrind (ctest -R unittest_ipaddr -T memcheck) reports many "Conditional jump or move depends on uninitialised value(s)" errors (tracker #64892).

Root cause: the tests build their own fixtures on the stack and leave fields uninitialised.

  • The struct ifaddrs fixtures are never zero-initialised, so ifa_flags is read uninitialised in grade_addr() (a few tests even did ifa_flags &= ~IFF_UP on an uninitialised value).
  • The ipv4() / ipv6() helpers only set the address family and address, leaving sin_port / sin_zero and sin6_port / sin6_flowinfo / sin6_scope_id uninitialised; those are later read when the addresses are formatted (getnameinfo).

Fix: value-initialise every struct ifaddrs fixture and memset() the sockaddr in the ipv4() / ipv6() helpers.

Before this change valgrind reported 64 errors from 7 contexts; after it, ERROR SUMMARY: 0 errors from 0 contexts and all 47 tests still pass.

Fixes: https://tracker.ceph.com/issues/64892

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)

Running unittest_ipaddr under valgrind reported many "Conditional jump or
move depends on uninitialised value(s)" errors (tracker ceph#64892).

The tests build their own `struct ifaddrs` and `struct sockaddr_in`/
`sockaddr_in6` fixtures on the stack. The `ifaddrs` structs were never
zero-initialised, so `ifa_flags` was read uninitialised in `grade_addr()`
(a few tests even did `ifa_flags &= ~IFF_UP` on an uninitialised value).
The `ipv4()`/`ipv6()` helpers only set the address family and address, so
`sin_port`/`sin_zero` and `sin6_port`/`sin6_flowinfo`/`sin6_scope_id`
stayed uninitialised and were later read when the addresses were formatted
(getnameinfo).

Value-initialise every `struct ifaddrs` fixture and memset the sockaddr in
the `ipv4()`/`ipv6()` helpers. With both changes valgrind reports 0 errors
and all 47 tests still pass.

Signed-off-by: Abraham Pérez <[email protected]>
@github-actions

github-actions Bot commented Nov 7, 2026

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.

@abrahamperz
abrahamperz marked this pull request as ready for review November 7, 2026 17:31
@abrahamperz

Copy link
Copy Markdown
Contributor Author

Closing this in favor of #72142, which already fixes the same uninitialised ifaddrs/sockaddr reads in test_ipaddr (see also #73603). No sense in keeping duplicates open. Thanks!

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.

1 participant