Skip to content

Fix potential null dereference in rd_kafka_assign_ranges() when member assignment lookup fails #5120

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lhywk
Copy link

@lhywk lhywk commented Jun 19, 2025

Describe

Hi,

In the function rd_kafka_assign_ranges(), a pointer member_assignment is obtained via a call to:

rd_kafka_find_member_assigned_partitions_pair_by_member_id()

This function may return NULL if the specified member_id has no matching entry in the list member_to_assigned_partitions.

Previously, the return value was used without checking for NULL:

rd_list_cnt(member_assignment->assigned_partitions);

This is unsafe because rd_list_cnt() directly accesses the internal field rl->rl_cnt without validating the pointer:

static RD_INLINE RD_UNUSED int rd_list_cnt(const rd_list_t *rl) {
    return rl->rl_cnt;
}

If member_assignment is NULL, this leads to an immediate null pointer dereference and undefined behavior.

Expected Behavior

If no assignment is found for a given member, the member should be skipped safely without any dereferencing of null pointers.

Actual Behavior

When rd_kafka_find_member_assigned_partitions_pair_by_member_id() returns NULL, the code previously proceeded to access member_assignment->assigned_partitions, resulting in undefined behavior due to null pointer dereference.

How to Reproduce

This issue can occur when:

  1. The member_to_assigned_partitions list does not contain an entry for a specific member_id.
  2. rd_kafka_find_member_assigned_partitions_pair_by_member_id() returns NULL.
  3. member_assignment->assigned_partitions is accessed unconditionally.
  4. This leads to a null pointer dereference inside rd_list_cnt().

By adding a null check and skipping such members, this patch avoids the unsafe behavior.

Thanks for reviewing.

@lhywk lhywk requested a review from a team as a code owner June 19, 2025 05:50
@confluent-cla-assistant
Copy link

confluent-cla-assistant bot commented Jun 19, 2025

🎉 All Contributor License Agreements have been signed. Ready to merge.
✅ lhywk
Please push an empty commit if you would like to re-run the checks to verify CLA status for all contributors.

@lhywk lhywk force-pushed the fix/rd_kafka_assign_ranges-null-check branch from c8cf10e to 397e607 Compare June 19, 2025 06:01
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.

1 participant