mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 08:42:39 +01:00 
			
		
		
		
	Fixed deserializeJson() silently accepting a Stream* (issue #978)
				
					
				
			This commit is contained in:
		| @@ -4,6 +4,7 @@ ArduinoJson: change log | |||||||
| HEAD | HEAD | ||||||
| ---- | ---- | ||||||
|  |  | ||||||
|  | * Fixed `deserializeJson()` silently accepting a `Stream*` (issue #978) | ||||||
| * Fixed invalid result from `operator|` (issue #981) | * Fixed invalid result from `operator|` (issue #981) | ||||||
|  |  | ||||||
| > ### BREAKING CHANGE | > ### BREAKING CHANGE | ||||||
|   | |||||||
| @@ -17,4 +17,4 @@ before_build: | |||||||
| build_script: | build_script: | ||||||
| - cmake --build . --config %CONFIGURATION% | - cmake --build . --config %CONFIGURATION% | ||||||
| test_script: | test_script: | ||||||
| - ctest --output-on-failure . | - ctest -C %CONFIGURATION% --output-on-failure . | ||||||
|   | |||||||
| @@ -6,6 +6,16 @@ | |||||||
|  |  | ||||||
| namespace ARDUINOJSON_NAMESPACE { | namespace ARDUINOJSON_NAMESPACE { | ||||||
|  |  | ||||||
|  | template <typename T> | ||||||
|  | struct IsCharOrVoid { | ||||||
|  |   static const bool value = | ||||||
|  |       is_same<T, void>::value || is_same<T, char>::value || | ||||||
|  |       is_same<T, unsigned char>::value || is_same<T, signed char>::value; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | template <typename T> | ||||||
|  | struct IsCharOrVoid<const T> : IsCharOrVoid<T> {}; | ||||||
|  |  | ||||||
| class UnsafeCharPointerReader { | class UnsafeCharPointerReader { | ||||||
|   const char* _ptr; |   const char* _ptr; | ||||||
|  |  | ||||||
| @@ -41,12 +51,16 @@ class SafeCharPointerReader { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| template <typename TChar> | template <typename TChar> | ||||||
| inline UnsafeCharPointerReader makeReader(TChar* input) { | inline typename enable_if<IsCharOrVoid<TChar>::value, | ||||||
|  |                           UnsafeCharPointerReader>::type | ||||||
|  | makeReader(TChar* input) { | ||||||
|   return UnsafeCharPointerReader(reinterpret_cast<const char*>(input)); |   return UnsafeCharPointerReader(reinterpret_cast<const char*>(input)); | ||||||
| } | } | ||||||
|  |  | ||||||
| template <typename TChar> | template <typename TChar> | ||||||
| inline SafeCharPointerReader makeReader(TChar* input, size_t n) { | inline | ||||||
|  |     typename enable_if<IsCharOrVoid<TChar>::value, SafeCharPointerReader>::type | ||||||
|  |     makeReader(TChar* input, size_t n) { | ||||||
|   return SafeCharPointerReader(reinterpret_cast<const char*>(input), n); |   return SafeCharPointerReader(reinterpret_cast<const char*>(input), n); | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -13,3 +13,24 @@ add_executable(MiscTests | |||||||
|  |  | ||||||
| target_link_libraries(MiscTests catch) | target_link_libraries(MiscTests catch) | ||||||
| add_test(Misc MiscTests) | add_test(Misc MiscTests) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | add_executable(Issue978 | ||||||
|  | 	Issue978.cpp | ||||||
|  | ) | ||||||
|  | set_target_properties(Issue978 | ||||||
|  | 	PROPERTIES | ||||||
|  |     	EXCLUDE_FROM_ALL TRUE | ||||||
|  |         EXCLUDE_FROM_DEFAULT_BUILD TRUE | ||||||
|  | ) | ||||||
|  | add_test( | ||||||
|  | 	NAME | ||||||
|  | 		Issue978 | ||||||
|  |     COMMAND | ||||||
|  |     	${CMAKE_COMMAND} --build . --target Issue978 --config $<CONFIGURATION> | ||||||
|  |     WORKING_DIRECTORY | ||||||
|  |     	${CMAKE_BINARY_DIR} | ||||||
|  | ) | ||||||
|  | set_tests_properties(Issue978  | ||||||
|  | 	PROPERTIES | ||||||
|  | 		WILL_FAIL TRUE) | ||||||
|   | |||||||
							
								
								
									
										13
									
								
								test/Misc/Issue978.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								test/Misc/Issue978.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | |||||||
|  | // ArduinoJson - arduinojson.org | ||||||
|  | // Copyright Benoit Blanchon 2014-2019 | ||||||
|  | // MIT License | ||||||
|  |  | ||||||
|  | #include <ArduinoJson.h> | ||||||
|  |  | ||||||
|  | struct Stream {}; | ||||||
|  |  | ||||||
|  | int main() { | ||||||
|  |   Stream* stream = 0; | ||||||
|  |   DynamicJsonDocument doc(1024); | ||||||
|  |   deserializeJson(doc, stream); | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user