Add NULL checks to prevent segfaults when Kafka metadata contains NULL #428
Conversation
…L values during broker restarts
There was a problem hiding this comment.
Pull request overview
Adds NULL pointer checks to prevent segmentation faults when Kafka metadata contains NULL values during broker restarts or metadata updates.
- Adds NULL checks for node pointers and host fields in
ToV8Object() - Adds NULL checks for leader, ISR, and replica nodes in
FromDescribeTopicsResult() - Fixes memory leaks by destroying partition lists when validation fails
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (offsetValue->IsObject()) { | ||
| v8::Local<v8::Object> offsetObject = offsetValue.As<v8::Object>(); | ||
| int64_t offset = GetParameter<int64_t>(offsetObject, "timestamp", 0); | ||
| toppar->offset = offset; | ||
| } else { | ||
| toppar->offset = 0; | ||
| } |
There was a problem hiding this comment.
The logic extracts a 'timestamp' parameter from the offset object but assigns it to toppar->offset. This is confusing - if the parameter name is 'timestamp', consider renaming the local variable to timestamp for clarity, or verify that 'timestamp' is the correct parameter name to extract.
There was a problem hiding this comment.
great, it solves an unhandled exception in case you pass an object without the offset property.
…L values during broker restarts
efdc2cf to
83ed71d
Compare
Pratyush Ranjan (PratRanj07)
left a comment
There was a problem hiding this comment.
LGTM!
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Emanuele Sabellico (emasab)
left a comment
There was a problem hiding this comment.
Thanks both! Sent these comments.
| if (offsetValue->IsObject()) { | ||
| v8::Local<v8::Object> offsetObject = offsetValue.As<v8::Object>(); | ||
| int64_t offset = GetParameter<int64_t>(offsetObject, "timestamp", 0); | ||
| toppar->offset = offset; | ||
| } else { | ||
| toppar->offset = 0; | ||
| } |
There was a problem hiding this comment.
great, it solves an unhandled exception in case you pass an object without the offset property.
Emanuele Sabellico (emasab)
left a comment
There was a problem hiding this comment.
LGTM. Thanks Kaushik, just run the linter as it's failing in the CI.
Pratyush Ranjan (PratRanj07)
left a comment
There was a problem hiding this comment.
LGTM! Thanks Kaushik Raina (@k-raina) !
Problem
Application crashes with segmentation fault when calling
AdminClient.describeTopics()during Kafka broker restarts. The crash occurs when converting node metadata to JavaScript objects.Root Cause: During broker restarts, Kafka metadata can contain NULL node pointers or NULL host fields. The code dereferenced these NULL pointers without checks, causing segfaults.
Replication steps
Solution
Added defensive NULL checks in two functions:
ToV8Object()- Check if node pointer and host field are NULL before accessingFromDescribeTopicsResult()- Check leader, ISR, and replica nodes for NULL before conversionNULL values are now safely converted to JavaScript
nullinstead of crashing.Testing
Without Fix
With Fix
No segfault noticed