From: Lennart Poettering Date: Fri, 12 Oct 2018 14:53:04 +0000 (+0200) Subject: json: add an assert_cc() check that validates _JSON_VARIANT_MAGIC_MAX X-Git-Tag: v240~473^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=085f3d6416c7af9247a76ca964f43a991574892f;p=thirdparty%2Fsystemd.git json: add an assert_cc() check that validates _JSON_VARIANT_MAGIC_MAX --- diff --git a/src/basic/json-internal.h b/src/basic/json-internal.h index 98e53ede10c..bf158bff0d4 100644 --- a/src/basic/json-internal.h +++ b/src/basic/json-internal.h @@ -37,6 +37,11 @@ assert_cc(sizeof(JsonValue) == 16U); #define JSON_VARIANT_MAGIC_EMPTY_OBJECT ((JsonVariant*) 9) #define _JSON_VARIANT_MAGIC_MAX ((JsonVariant*) 10) +/* This is only safe as long as we don't define more than 4K magic pointers, i.e. the page size of the simplest + * architectures we support. That's because we rely on the fact that malloc() will never allocate from the first memory + * page, as it is a faulting page for catching NULL pointer dereferences. */ +assert_cc((uintptr_t) _JSON_VARIANT_MAGIC_MAX < 4096U); + enum { /* JSON tokens */ JSON_TOKEN_END, JSON_TOKEN_COLON,