mirror of
https://github.com/Icinga/icinga2.git
synced 2026-07-10 09:31:04 -04:00
The recursion depth limit added to JsonDecode() in 2.16.2 gave the C++
function a second parameter with a default value. Function pointers do not
carry default arguments, so the DSL function binding deduced an arity of 2
via boost::function_types::function_arity and required two arguments. As a
result `Json.decode("...")` failed with "Too few arguments for function",
an undocumented breaking change in a patch release.
Wrap JsonDecode() in a single-argument shim (mirroring the existing
JsonEncodeShim) so the registered function keeps its one-parameter contract
while still applying the default depth limit internally.
refs #10913
39 lines
1.1 KiB
C++
39 lines
1.1 KiB
C++
// SPDX-FileCopyrightText: 2012 Icinga GmbH <https://icinga.com>
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#include "base/dictionary.hpp"
|
|
#include "base/function.hpp"
|
|
#include "base/functionwrapper.hpp"
|
|
#include "base/scriptframe.hpp"
|
|
#include "base/initialize.hpp"
|
|
#include "base/json.hpp"
|
|
|
|
using namespace icinga;
|
|
|
|
static String JsonEncodeShim(const Value& value)
|
|
{
|
|
return JsonEncode(value);
|
|
}
|
|
|
|
static Value JsonDecodeShim(const String& data)
|
|
{
|
|
/* Wrap JsonDecode() so that the DSL function keeps its single-argument
|
|
* signature. JsonDecode()'s depthLimit parameter has a default value, but
|
|
* function pointers don't carry defaults, so binding it directly would make
|
|
* depthLimit a required argument and break Json.decode("..."). See #10913.
|
|
*/
|
|
return JsonDecode(data);
|
|
}
|
|
|
|
INITIALIZE_ONCE([]() {
|
|
Namespace::Ptr jsonNS = new Namespace(true);
|
|
|
|
/* Methods */
|
|
jsonNS->Set("encode", new Function("Json#encode", JsonEncodeShim, { "value" }, true));
|
|
jsonNS->Set("decode", new Function("Json#decode", JsonDecodeShim, { "value" }, true));
|
|
|
|
jsonNS->Freeze();
|
|
|
|
Namespace::Ptr systemNS = ScriptGlobal::Get("System");
|
|
systemNS->Set("Json", jsonNS, true);
|
|
});
|