]> git.ipfire.org Git - thirdparty/systemd.git/commit
sd-json: make sure all dispatch helpers do something sensible in case of "null" JSON...
authorLennart Poettering <lennart@poettering.net>
Fri, 24 Oct 2025 07:57:48 +0000 (09:57 +0200)
committerLennart Poettering <lennart@poettering.net>
Sat, 1 Nov 2025 20:43:37 +0000 (21:43 +0100)
commite01f8990f1e535c367bbab9018ed2d8def1dd6fa
tree9f768fddade6214c0ae2a5dad528f9c6f5f42579
parent3cc3b469cc45edd58dc3aa90aeb4a42c524d66f1
sd-json: make sure all dispatch helpers do something sensible in case of "null" JSON value

Most of our dispatch helpers already do something useful in case they
are invoked on a null JSON value: they translate this to the appropriate
niche value for the type, if there is one.

Add the same for *all* dispatchers we have, to make this fully
systematic.

For various types it's not always clear which niche value to pick. I
opted for UINT{8,16,32,64}_MAX for the various unsigned integers, which
maps our own use in most cases. I opted for -1 for the various signed
integer types. For arrays/blobs of stuff I opted for the empty
array/blob, and for booleans I opted for false.

Of course, in various cases this is not going to be the right niche
value, but that's entirely fine, after all before a json value reaches a
dispatcher function it must pass one of two type checks first:

1. Either the .type field of sd_json_dispatch_field must be
   _SD_JSON_VARIANT_TYPE_INVALID to not do a type check at all

2. Or the .type field is set, but then the SD_JSON_NULLABLE flag must be
   set in .flags.

This means, accidentally generating the niche values on null is not
really likely.
src/libsystemd/sd-json/json-util.c
src/libsystemd/sd-json/sd-json.c