mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Increased default nesting limit to 50 when compiled for a computer (issue #349)
This commit is contained in:
		| @@ -1,6 +1,11 @@ | ||||
| ArduinoJson: change log | ||||
| ======================= | ||||
|  | ||||
| HEAD | ||||
| ---- | ||||
|  | ||||
| * Increased default nesting limit to 50 when compiled for a computer (issue #349) | ||||
|  | ||||
| v5.6.7 | ||||
| ------ | ||||
|  | ||||
|   | ||||
| @@ -42,6 +42,11 @@ | ||||
| #endif | ||||
| #endif | ||||
|  | ||||
| // low value to prevent stack overflow | ||||
| #ifndef ARDUINOJSON_DEFAULT_NESTING_LIMIT | ||||
| #define ARDUINOJSON_DEFAULT_NESTING_LIMIT 10 | ||||
| #endif | ||||
|  | ||||
| #else  // assume this is a computer | ||||
|  | ||||
| // on a computer we have plenty of memory so we can use doubles | ||||
| @@ -82,6 +87,11 @@ | ||||
| #define ARDUINOJSON_ENABLE_ALIGNMENT 1 | ||||
| #endif | ||||
|  | ||||
| // on a computer, we should have a lot of space on the stack | ||||
| #ifndef ARDUINOJSON_DEFAULT_NESTING_LIMIT | ||||
| #define ARDUINOJSON_DEFAULT_NESTING_LIMIT 50 | ||||
| #endif | ||||
|  | ||||
| #endif | ||||
|  | ||||
| #if ARDUINOJSON_USE_LONG_LONG && ARDUINOJSON_USE_INT64 | ||||
|   | ||||
| @@ -117,7 +117,9 @@ class JsonBuffer { | ||||
|   char *strdup(const char *src) { | ||||
|     return src ? strdup(src, strlen(src)) : NULL; | ||||
|   } | ||||
|   char *strdup(const String &src) { return strdup(src.c_str(), src.length()); } | ||||
|   char *strdup(const String &src) { | ||||
|     return strdup(src.c_str(), src.length()); | ||||
|   } | ||||
|  | ||||
|   // Allocates n bytes in the JsonBuffer. | ||||
|   // Return a pointer to the allocated memory or NULL if allocation fails. | ||||
| @@ -139,9 +141,8 @@ class JsonBuffer { | ||||
|  | ||||
|   // Default value of nesting limit of parseArray() and parseObject(). | ||||
|   // | ||||
|   // The nesting limit is a contain on the level of nesting allowed in the | ||||
|   // JSON | ||||
|   // string. | ||||
|   // The nesting limit is a constrain on the level of nesting allowed in the | ||||
|   // JSON string. | ||||
|   // If set to 0, only a flat array or objects can be parsed. | ||||
|   // If set to 1, the object can contain nested arrays or objects but only 1 | ||||
|   // level deep. | ||||
| @@ -150,7 +151,7 @@ class JsonBuffer { | ||||
|   // The purpose of this feature is to prevent stack overflow that could | ||||
|   // lead to | ||||
|   // a security risk. | ||||
|   static const uint8_t DEFAULT_LIMIT = 10; | ||||
|   static const uint8_t DEFAULT_LIMIT = ARDUINOJSON_DEFAULT_NESTING_LIMIT; | ||||
| }; | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -5,12 +5,14 @@ | ||||
| // https://github.com/bblanchon/ArduinoJson | ||||
| // If you like this project, please add a star! | ||||
|  | ||||
| #include <gtest/gtest.h> | ||||
| #include <ArduinoJson.h> | ||||
| #include <gtest/gtest.h> | ||||
|  | ||||
| class JsonParser_Array_Tests : public testing::Test { | ||||
|  protected: | ||||
|   void whenInputIs(const char *json) { strcpy(_jsonString, json); } | ||||
|   void whenInputIs(const char *json) { | ||||
|     strcpy(_jsonString, json); | ||||
|   } | ||||
|  | ||||
|   void whenInputIs(const char *json, size_t len) { | ||||
|     memcpy(_jsonString, json, len); | ||||
| @@ -27,7 +29,9 @@ class JsonParser_Array_Tests : public testing::Test { | ||||
|     EXPECT_EQ(0, _array->size()); | ||||
|   } | ||||
|  | ||||
|   void sizeMustBe(int expected) { ASSERT_EQ(expected, _array->size()); } | ||||
|   void sizeMustBe(int expected) { | ||||
|     ASSERT_EQ(expected, _array->size()); | ||||
|   } | ||||
|  | ||||
|   template <typename T> | ||||
|   void firstElementMustBe(T expected) { | ||||
| @@ -346,3 +350,8 @@ TEST_F(JsonParser_Array_Tests, UnfinishedCComment) { | ||||
|   whenInputIs("[/*COMMENT]"); | ||||
|   parseMustFail(); | ||||
| } | ||||
|  | ||||
| TEST_F(JsonParser_Array_Tests, DeeplyNested) { | ||||
|   whenInputIs("[[[[[[[[[[[[[[[[[[[\"Not too deep\"]]]]]]]]]]]]]]]]]]]"); | ||||
|   parseMustSucceed(); | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user