-
Notifications
You must be signed in to change notification settings - Fork 215
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
Fix crash in Buffer with null pointer and non-zero length #88
Conversation
Why would you construct a buffer on a null pointer but with a size larger than 0? Sounds like that construction is just bogus from the user's side. |
It definitely is a bogus construction but in case this happens it's nice not to crash. If the user prints out the buffer and sees empty string instead of some expected value at least the application can continue, you can log the error, and in this case, receive an empty payload. Alternatively you can throw in the constructor but definitely not assert as it's only good for debug builds. You need some runtime guarantees in release mode as well. |
I think I would rather throw on construction. A buffer constructed like that is just bogus and here you're basically hiding away the fact that the buffer is broken, so the user won't even realize (assuming they only convert them to strings). |
7f30e0d
to
7108134
Compare
Ok i made the change. Initially i put a more restrictive check in the constructor to also validate
Essentially when there's an error, the payload contains the error string and the I wonder if in this case we should wait for this fix or try to calculate |
Well, that makes sense. You should be able to construct a buffer with length 0 and a valid pointer, you could end up doing this if you have some pointer and you decrease your length enough that it reaches 0. Checking for length > 0 is the correct thing to do. |
Yes agreed! The librdkafka bug will stay however as it's incorrectly set. |
When a
Buffer
is built with null ptr and size > 0, theoperator bool
return true but any conversion tostring
crashes.