Fix potential null dereference in rd_kafka_assign_ranges() when member assignment lookup fails #5120
+3
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Describe
Hi,
In the function
rd_kafka_assign_ranges()
, a pointermember_assignment
is obtained via a call to:rd_kafka_find_member_assigned_partitions_pair_by_member_id()
This function may return
NULL
if the specifiedmember_id
has no matching entry in the listmember_to_assigned_partitions
.Previously, the return value was used without checking for NULL:
This is unsafe because
rd_list_cnt()
directly accesses the internal fieldrl->rl_cnt
without validating the pointer:If
member_assignment
isNULL
, 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()
returnsNULL
, the code previously proceeded to accessmember_assignment->assigned_partitions
, resulting in undefined behavior due to null pointer dereference.How to Reproduce
This issue can occur when:
member_to_assigned_partitions
list does not contain an entry for a specificmember_id
.rd_kafka_find_member_assigned_partitions_pair_by_member_id()
returnsNULL
.member_assignment->assigned_partitions
is accessed unconditionally.rd_list_cnt()
.By adding a null check and skipping such members, this patch avoids the unsafe behavior.
Thanks for reviewing.