From 6dab443789f0f1086000e7ddb60437f7a228a61e Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Thu, 19 Oct 2023 21:00:21 -0700 Subject: [PATCH] Dictionary: add defensive coding checks. --- src/sl/Dictionary.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/sl/Dictionary.cc b/src/sl/Dictionary.cc index 0cb7c24..9d8db75 100644 --- a/src/sl/Dictionary.cc +++ b/src/sl/Dictionary.cc @@ -158,6 +158,10 @@ operator<<(std::ostream &os, const Dictionary &dictionary) uint8_t *cursor = (dictionary.arena).Start(); TLV::Record rec; + if (cursor == nullptr) { + return os; + } + TLV::ReadFromMemory(rec, cursor); if (rec.Tag == TLV::TAG_EMPTY) { os << "\t(NONE)" << std::endl; @@ -168,7 +172,11 @@ operator<<(std::ostream &os, const Dictionary &dictionary) os << "\t" << rec.Val << "->"; cursor = TLV::SkipRecord(rec, cursor); TLV::ReadFromMemory(rec, cursor); - os << rec.Val << std::endl; + if (cursor == nullptr) { + os << "*** CORRUPT DICTIONARY ***\n"; + break; + } + os << rec.Val << "\n"; cursor = TLV::SkipRecord(rec, cursor); TLV::ReadFromMemory(rec, cursor); }