8000 Fixed `deserializeJson()` silently accepting a `Stream*` (issue #978) · joglosemarduino/ArduinoJson@2af003e · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 2af003e

Browse files
committed
Fixed deserializeJson() silently accepting a Stream* (issue bblanchon#978)
1 parent eaf55e1 commit 2af003e

File tree

5 files changed

+52
-3
lines changed

5 files changed

+52
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ ArduinoJson: change log
44
HEAD
55
----
66

7+
* Fixed `deserializeJson()` silently accepting a `Stream*` (issue #978)
78
* Fixed invalid result from `operator|` (issue #981)
89

910
> ### BREAKING CHANGE

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ before_build:
1717
build_script:
1818
- cmake --build . --config %CONFIGURATION%
1919
test_script:
20-
- ctest --output-on-failure .
20+
- ctest -C %CONFIGURATION% --output-on-failure .

src/ArduinoJson/Deserialization/CharPointerReader.hpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66

77
namespace ARDUINOJSON_NAMESPACE {
88

9+
template <typename T>
10+
struct IsCharOrVoid {
11+
static const bool value =
12+
is_same<T, void>::value || is_same<T, char>::value ||
13+
is_same<T, unsigned char>::value || is_same<T, signed char>::value;
14+
};
15+
16+
template <typename T>
17+
struct IsCharOrVoid<const T> : IsCharOrVoid<T> {};
18+
919
class UnsafeCharPointerReader {
1020
const char* _ptr;
1121

@@ -41,12 +51,16 @@ class SafeCharPointerReader {
4151
};
4252

4353
template <typename TChar>
44-
inline UnsafeCharPointerReader makeReader(TChar* input) {
54+
inline typename enable_if<IsCharOrVoid<TChar>::value,
55+
UnsafeCharPointerReader>::type
56+
makeReader(TChar* input) {
4557
return UnsafeCharPointerReader(reinterpret_cast<const char*>(input));
4658
}
4759

4860
template <typename TChar>
49-
inline SafeCharPointerReader makeReader(TChar* input, size_t n) {
61+
inline
62+
typename enable_if<IsCharOrVoid<TChar>::value, SafeCharPointerReader>::type
63+
makeReader(TChar* input, size_t n) {
5064
return SafeCharPointerReader(reinterpret_cast<const char*>(input), n);
5165
}
5266

test/Misc/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,24 @@ add_executable(MiscTests
1313

1414
target_link_libraries(MiscTests catch)
1515
add_test(Misc MiscTests)
16+
17+
18+
add_executable(Issue978
19+
Issue978.cpp
20+
)
21+
set_target_properties(Issue978
22+
PROPERTIES
23+
EXCLUDE_FROM_ALL TRUE
24+
EXCLUDE_FROM_DEFAULT_BUILD TRUE
25+
)
26+
add_test(
27+
NAME
28+
Issue978
29+
COMMAND
30+
${CMAKE_COMMAND} --build . --target Issue978 --config $<CONFIGURATION>
31+
WORKING_DIRECTORY
32+
${CMAKE_BINARY_DIR}
33+
)
34+
set_tests_properties(Issue978
35+
PROPERTIES
36+
WILL_FAIL TRUE)

test/Misc/Issue978.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// ArduinoJson - arduinojson.org
2+
// Copyright Benoit Blanchon 2014-2019
3+
// MIT License
4+
5+
#include <ArduinoJson.h>
< 5C9F /td>6+
7+
struct Stream {};
8+
9+
int main() {
10+
Stream* stream = 0;
11+
DynamicJsonDocument doc(1024);
12+
deserializeJson(doc, stream);
13+
}

0 commit comments

Comments
 (0)
0