fix(types): initialize Quote field in Message.UnmarshalJSON#42
Conversation
Initialize the Quote field to avoid nil pointer dereferences when unmarshaling messages with quote data. Previously, if a message contained quote information, the Quote field would remain nil, causing potential panics when accessing quote properties. Add test case to verify that messages with quotes are properly unmarshaled and the Quote field is correctly initialized.
|
thanks for jumping on this. i can confirm this patch fixes the quoted-message panic path, but I think the unconditional allocation changes the semantics for messages without a quote. right now the PR does: it means i think safer fix is to allocate only when a non-null quote is present, and explicitly clear stale values on reused it can preserve the expected optional-field behavior: no quote field => msg.Quote == nil it would also be good to add tests for the absent and null cases, not just the quoted case. |
|
Hey @ccclxxiii,
Thanks for the heads up, I totally glossed over these cases! Just noticed an NPE and rushed to fix it without properly think ahead. Will try to update the PR applying your better thought suggestions + adding some tests to it asap |
@ccclxxiii this is unnecessary or??? go always assign variables IIRC so a pointer is always nil without needing initialization 🤔 @Polpetta, @ccclxxiii thanks for bringing this up and trying to fix, but this code is automatically generated from the OpenRPC schema specification file that deltachat-rpc-server binary generates I have fixed the generator at chatmail/dcrpcgen#9 and I created a PR updating the auto-generated code and adding a test for this problem at #43 we can close this one here, and sorry for taking so long to look into this and reply! thanks a lot! 🙏 |
|
Hey @adbenitez no issue whatsoever! Thanks for having a look at this and spending time in finding and fixing this issue at the root 🙌 Could you please make a release for this? So that people can update their rpc-clients/bots that rely on reply via quote |
I've initialised the Quote field to avoid nil pointer dereferences when unmarshaling messages with quote data. Previously, if a message contained quote information, the Quote field would remain nil, causing potential panics when accessing quote properties.
Add test case to verify that messages with quotes are properly unmarshaled and the Quote field is correctly initialized. I've tried to keep the same style of yours, hope it's good enough.
Note
I've tested this manually as well by spinning up my bot locally and it seems to do the trick, with the bug disappearing completely.
Closes #41