From 13f2e44aca97f470ce569340ae6a6681ab63a7f8 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Fri, 13 Aug 2021 17:45:23 +1000 Subject: [PATCH] Have JSON fuzzer segfault on internal errors --- fuzz/c/std/json_fuzzer.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/fuzz/c/std/json_fuzzer.cc b/fuzz/c/std/json_fuzzer.cc index 727411f5..50b66fe8 100644 --- a/fuzz/c/std/json_fuzzer.cc +++ b/fuzz/c/std/json_fuzzer.cc @@ -441,6 +441,7 @@ class Callbacks : public wuffs_aux::DecodeJsonCallbacks { std::string Pop(uint32_t flags) override { m_depth--; if (m_depth < 0) { + fprintf(stderr, "negative depth\n"); intentional_segfault(); } return ""; @@ -449,7 +450,15 @@ class Callbacks : public wuffs_aux::DecodeJsonCallbacks { void Done(wuffs_aux::DecodeJsonResult& result, wuffs_aux::sync_io::Input& input, wuffs_aux::IOBuffer& buffer) override { - if (result.error_message.empty() && (m_depth != 0)) { + if (result.error_message.empty()) { + if (m_depth != 0) { + fprintf(stderr, "no error message but final depth is non-zero\n"); + intentional_segfault(); + } + } else if (result.error_message.find("internal error:") != + std::string::npos) { + fprintf(stderr, "internal errors shouldn't occur: \"%s\"\n", + result.error_message.c_str()); intentional_segfault(); } }