Handle null group name to prevent segfault in Admin list_consumer_group_offsets() #2118
 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.    
 


What
Problem
User reported a segmentation fault when calling
list_consumer_group_offsets()on non-existing consumer groups in v2.10.0. The process crashed instead of raising an exception.Investigation
Normal behavior verified: When calling
list_consumer_group_offsets()on a non-existing group, the API successfully returns an empty list (confluent-kafka-python/src/confluent_kafka/src/Admin.c
Line 5011 in 06c0744
Why the segfault occur (theory): Since the normal "non-existing group" path works correctly, the crash must occur in error scenarios where librdkafka encounters internal failures. Through code analysis, we identified a vulnerability: the C binding passes
rd_kafka_group_result_name()directly toPyUnicode_FromString()without NULL checking (confluent-kafka-python/src/confluent_kafka/src/Admin.c
Line 4539 in 06c0744
rd_kafka_group_result_name()returns NULL (possible in edge cases like network timeouts, coordinator unavailability, broker communication failures, or race conditions in error handling), this causes a NULL pointer dereference inPyUnicode_FromString(), resulting in SIGSEGV.Solution
In
Admin_c_SingleGroupResult_to_py(), add defensive check for NULL group_name.Checklist
References
JIRA: https://confluentinc.atlassian.net/browse/NONJAVACLI-4100
Issue: #1982
Test & Review
Open questions / Follow-ups