aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2021-01-05 17:54:25 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2021-01-05 17:54:25 +0000
commitb9092ddb5c2c1f26788568ce88d9d9619cbb8ce5 (patch)
tree14bc9ed5eb1649dae50334b2e22c70f8921b7ec1
parentMerge pull request #7271 (diff)
downloadmonero-b9092ddb5c2c1f26788568ce88d9d9619cbb8ce5.tar.xz
epee: also limit number of strings in portable_storage
They require at least 24 bytes
-rw-r--r--contrib/epee/include/storages/portable_storage_from_bin.h12
1 files changed, 11 insertions, 1 deletions
diff --git a/contrib/epee/include/storages/portable_storage_from_bin.h b/contrib/epee/include/storages/portable_storage_from_bin.h
index dfd815f97..7eeced6ff 100644
--- a/contrib/epee/include/storages/portable_storage_from_bin.h
+++ b/contrib/epee/include/storages/portable_storage_from_bin.h
@@ -38,7 +38,8 @@
#define EPEE_PORTABLE_STORAGE_RECURSION_LIMIT_INTERNAL 100
#endif
#define EPEE_PORTABLE_STORAGE_OBJECT_LIMIT_INTERNAL 65536
-#define EPEE_PORTABLE_STORAGE_OBJECT_FIELD_LIMIT_INTERNAL 262144
+#define EPEE_PORTABLE_STORAGE_OBJECT_FIELD_LIMIT_INTERNAL 65536
+#define EPEE_PORTABLE_STORAGE_STRING_LIMIT_INTERNAL 65536 // does not include field names
namespace epee
{
@@ -106,6 +107,7 @@ namespace epee
size_t m_recursion_count;
size_t m_objects;
size_t m_fields;
+ size_t m_strings;
};
inline throwable_buffer_reader::throwable_buffer_reader(const void* ptr, size_t sz)
@@ -119,6 +121,7 @@ namespace epee
m_recursion_count = 0;
m_objects = 0;
m_fields = 0;
+ m_strings = 0;
}
inline
void throwable_buffer_reader::read(void* target, size_t count)
@@ -172,6 +175,11 @@ namespace epee
CHECK_AND_ASSERT_THROW_MES(size <= EPEE_PORTABLE_STORAGE_OBJECT_LIMIT_INTERNAL - m_objects, "Too many objects");
m_objects += size;
}
+ else if (std::is_same<type_name, std::string>())
+ {
+ CHECK_AND_ASSERT_THROW_MES(size <= EPEE_PORTABLE_STORAGE_STRING_LIMIT_INTERNAL - m_strings, "Too many strings");
+ m_strings += size;
+ }
sa.reserve(size);
//TODO: add some optimization here later
@@ -238,6 +246,8 @@ namespace epee
inline storage_entry throwable_buffer_reader::read_se<std::string>()
{
RECURSION_LIMITATION();
+ CHECK_AND_ASSERT_THROW_MES(m_strings + 1 <= EPEE_PORTABLE_STORAGE_STRING_LIMIT_INTERNAL, "Too many strings");
+ m_strings += 1;
return storage_entry(read<std::string>());
}