Fix some json schema validation bugs
There were a couple of places where we would add null objects when
they were not allowed. Fix them.
Change-Id: I7c4c12ea1fa2913014e79603995267a9e560e288
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/tests/fuzz_cper_buf_to_ir.cpp b/tests/fuzz_cper_buf_to_ir.cpp
index 586c2ba..4baef7b 100644
--- a/tests/fuzz_cper_buf_to_ir.cpp
+++ b/tests/fuzz_cper_buf_to_ir.cpp
@@ -1,11 +1,28 @@
#include "libcper/cper-parse.h"
+#include "test-utils.hpp"
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
json_object *ir = cper_buf_to_ir(data, size);
- if (ir != NULL) {
- json_object_put(ir);
+ if (ir == NULL) {
+ return 0;
}
+ char *str = strdup(json_object_to_json_string(ir));
+
+ nlohmann::json jsonData = nlohmann::json::parse(str, nullptr, false);
+ free(str);
+ assert(jsonData.is_discarded() == false);
+ std::string error_message;
+ static std::unique_ptr<valijson::Schema> schema =
+ load_schema(AddRequiredProps::NO, 0);
+
+ int valid = schema_validate_from_file(*schema, jsonData, error_message);
+ if (!valid) {
+ std::cout << "JSON: " << jsonData.dump(4) << std::endl;
+ std::cout << "Error: " << error_message << std::endl;
+ }
+ assert(valid);
+ json_object_put(ir);
return 0;
}