nats-io / nats-server

High-Performance server for NATS.io, the cloud and edge native messaging system.
https://nats.io
Apache License 2.0
16.01k stars 1.41k forks source link

Fix nil pointer dereference on Placement #5996

Closed Jarema closed 1 month ago

Jarema commented 1 month ago

The check for empty object exposed a lack of check for *Placement before accessing its fields. This commit properly fixes it.

Signed-off-by: Tomasz Pietrek tomasz@nats.io

wallyqs commented 1 month ago

think we need coverage of sending empty objects on the other endpoints that might have been relying on filtering out empty fields.

also for this one need a test of sending unitialized placement like {“placement”: null}

Jarema commented 1 month ago

Will add a test. Did a brief check of others usages and it seems fine, but will test to be sure.

Jarema commented 1 month ago

Added a test, but I wonder if it makes sense to have it - empty object test achieves the same as JSApiLeaderStepdownRequest{Placement: nil}.

Jarema commented 1 month ago

Checked other endpoints that are using new function. We do not have pointers in them.

wallyqs commented 1 month ago

@Jarema you're right in this case placement has omitempty so result would be the same