bej_decoder_json: Add a limit on # of 0s in "real"
We have count the number of 0s in real numbers to add to the output
string. To prevent OOM from many 0s, add a limit.
Tested: Add unit test
Change-Id: I5e298554cf9d93b3f7ab86cac5b0b0a6f443716b
Signed-off-by: Brandon Kim <brandonkim@google.com>
diff --git a/src/bej_decoder_json.cpp b/src/bej_decoder_json.cpp
index 5f8ddac..9fceeba 100644
--- a/src/bej_decoder_json.cpp
+++ b/src/bej_decoder_json.cpp
@@ -202,6 +202,12 @@
struct BejJsonParam* params =
reinterpret_cast<struct BejJsonParam*>(dataPtr);
+ // Sanity check for zeroCount
+ if (value->zeroCount > 100)
+ {
+ return bejErrorInvalidSize;
+ }
+
addPropertyNameToOutput(params, propertyName);
params->output->append(std::to_string(value->whole));
params->output->push_back('.');