summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-10-26 15:45:49 +0200
committerLennart Poettering <lennart@poettering.net>2021-10-26 22:26:27 +0200
commit8f1daefce6e952f2fad9510e5101b5fc675d363f (patch)
tree726aa1f3673786c10e53bd94994f2057c66338e4 /src
parenttest: add a missing `udevadm settle` to the multipath test case (diff)
downloadsystemd-8f1daefce6e952f2fad9510e5101b5fc675d363f.tar.xz
systemd-8f1daefce6e952f2fad9510e5101b5fc675d363f.zip
json: do something remotely reasonable when we see NaN/infinity
JSON doesn't have NaN/infinity/-infinity concepts in the spec. Implementations vary what they do with it. JSON5 + Python simply generate special words "NAN" and "Inifinity" from it. Others generate "null" for it. At this point we never actually want to output this, so let's be conservative and generate RFC compliant JSON, i.e. convert to null. One day should JSON5 actually become a thing we can revisit this, but in that case we should implement things via a flag, and only optinally process nan/infinity/-infinity. This patch is extremely simple: whenever accepting a nan/infinity/-infinity from outside it converts it to NULL. I.e. we convert on input, not output.
Diffstat (limited to 'src')
-rw-r--r--src/shared/json.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/shared/json.c b/src/shared/json.c
index 0282992960..1bb95078cb 100644
--- a/src/shared/json.c
+++ b/src/shared/json.c
@@ -359,6 +359,12 @@ int json_variant_new_real(JsonVariant **ret, long double d) {
}
REENABLE_WARNING;
+ /* JSON doesn't know NaN, +Infinity or -Infinity. Let's silently convert to 'null'. */
+ if (isnan(d) || isinf(d)) {
+ *ret = JSON_VARIANT_MAGIC_NULL;
+ return 0;
+ }
+
r = json_variant_new(&v, JSON_VARIANT_REAL, sizeof(d));
if (r < 0)
return r;