Skip to content

Commit 0dd6231

Browse files
committed
Forbid deserializeJson(JsonArray|JsonObject, ...)
Closes #2135
1 parent 20219d7 commit 0dd6231

File tree

5 files changed

+28
-9
lines changed

5 files changed

+28
-9
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
ArduinoJson: change log
22
=======================
33

4+
HEAD
5+
----
6+
7+
* Forbid `deserializeJson(JsonArray|JsonObject, ...)` (issue #2135)
8+
49
v7.2.0 (2024-09-18)
510
------
611

extras/tests/FailingBuilds/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@ build_should_fail(variant_as_char)
3434

3535
add_executable(assign_char assign_char.cpp)
3636
build_should_fail(assign_char)
37+
38+
add_executable(deserialize_object deserialize_object.cpp)
39+
build_should_fail(deserialize_object)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// ArduinoJson - https://arduinojson.org
2+
// Copyright © 2014-2024, Benoit BLANCHON
3+
// MIT License
4+
5+
#include <ArduinoJson.h>
6+
7+
// See issue #2135
8+
9+
int main() {
10+
JsonObject obj;
11+
deserializeJson(obj, "");
12+
}

src/ArduinoJson/Deserialization/deserialize.hpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,10 @@ struct first_or_void<T, Rest...> {
2424

2525
// A meta-function that returns true if T is a valid destination type for
2626
// deserialize()
27-
template <class T, class = void>
28-
struct is_deserialize_destination : false_type {};
29-
3027
template <class T>
31-
struct is_deserialize_destination<
32-
T, enable_if_t<is_same<decltype(VariantAttorney::getResourceManager(
33-
detail::declval<T&>())),
34-
ResourceManager*>::value>> : true_type {};
28+
using is_deserialize_destination =
29+
bool_constant<is_base_of<JsonDocument, remove_cv_t<T>>::value ||
30+
IsVariant<T>::value>;
3531

3632
template <typename TDestination>
3733
inline void shrinkJsonDocument(TDestination&) {

src/ArduinoJson/Polyfills/type_traits/integral_constant.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ struct integral_constant {
1313
static const T value = v;
1414
};
1515

16-
typedef integral_constant<bool, true> true_type;
17-
typedef integral_constant<bool, false> false_type;
16+
template <bool B>
17+
using bool_constant = integral_constant<bool, B>;
18+
19+
using true_type = bool_constant<true>;
20+
using false_type = bool_constant<false>;
1821

1922
ARDUINOJSON_END_PRIVATE_NAMESPACE

0 commit comments

Comments
 (0)