From 2615649268149085305697417161236513483672 Mon Sep 17 00:00:00 2001 From: Glenn Smith Date: Wed, 22 Mar 2023 20:07:51 -0400 Subject: Fix crashes in DebugInfo::GetXByY calls when the result is null --- debuginfo.cpp | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'debuginfo.cpp') diff --git a/debuginfo.cpp b/debuginfo.cpp index 271aff09..c2079824 100644 --- a/debuginfo.cpp +++ b/debuginfo.cpp @@ -60,6 +60,9 @@ vector DebugInfo::GetTypes(const string& parserName) const BNNameAndType* nameAndTypes = BNGetDebugTypes(m_object, parserName.size() == 0 ? nullptr : parserName.c_str(), &count); + if (nameAndTypes == nullptr) + return {}; + vector result; for (size_t i = 0; i < count; ++i) { @@ -78,6 +81,9 @@ vector DebugInfo::GetFunctions(const string& parserName) cons BNDebugFunctionInfo* functions = BNGetDebugFunctions(m_object, parserName.size() == 0 ? nullptr : parserName.c_str(), &count); + if (functions == nullptr) + return {}; + vector result; for (size_t i = 0; i < count; ++i) { @@ -96,18 +102,21 @@ vector DebugInfo::GetFunctions(const string& parserName) cons vector DebugInfo::GetDataVariables(const string& parserName) const { size_t count; - BNDataVariableAndName* variableAndNames = + BNDataVariableAndName* variablesAndName = BNGetDebugDataVariables(m_object, parserName.size() == 0 ? nullptr : parserName.c_str(), &count); + if (variablesAndName == nullptr) + return {}; + vector result; for (size_t i = 0; i < count; ++i) { - result.emplace_back(variableAndNames[i].address, - Confidence(new Type(BNNewTypeReference(variableAndNames[i].type)), variableAndNames[i].typeConfidence), - variableAndNames[i].autoDiscovered, variableAndNames[i].name); + result.emplace_back(variablesAndName[i].address, + Confidence(new Type(BNNewTypeReference(variablesAndName[i].type)), variablesAndName[i].typeConfidence), + variablesAndName[i].autoDiscovered, variablesAndName[i].name); } - BNFreeDataVariablesAndName(variableAndNames, count); + BNFreeDataVariablesAndName(variablesAndName, count); return result; } @@ -155,6 +164,9 @@ vector>> DebugInfo::GetTypesByName(const string& name) c size_t count; BNNameAndType* namesAndTypes = BNGetDebugTypesByName(m_object, name.c_str(), &count); + if (namesAndTypes == nullptr) + return {}; + vector>> result; for (size_t i = 0; i < count; ++i) { @@ -172,6 +184,9 @@ vector>> DebugInfo::GetDataVariablesByName(con size_t count; BNDataVariableAndName* variablesAndName = BNGetDebugDataVariablesByName(m_object, name.c_str(), &count); + if (variablesAndName == nullptr) + return {}; + vector>> result; for (size_t i = 0; i < count; ++i) { @@ -190,6 +205,9 @@ vector>> DebugInfo::GetDataVariablesByAddress(co size_t count; BNDataVariableAndNameAndDebugParser* variablesAndName = BNGetDebugDataVariablesByAddress(m_object, address, &count); + if (variablesAndName == nullptr) + return {}; + vector>> result; for (size_t i = 0; i < count; ++i) { -- cgit v1.3.1