summaryrefslogtreecommitdiff
path: root/binaryview.cpp
diff options
context:
space:
mode:
authorJosh F <josh@vector35.com>2022-05-19 18:36:58 -0400
committerJosh F <josh@vector35.com>2022-05-19 18:36:58 -0400
commit904bd16ad332f1f40d2ea5c1862a4da8a984e004 (patch)
tree3f4eebcf9d96d7e70d92861cee5674e6f8ed18f8 /binaryview.cpp
parentb3af14e545ab56c702fc23f75bd94dfb7a12749d (diff)
Fix case where BinaryNinja::OpenView can be called with nullptr as view
Diffstat (limited to 'binaryview.cpp')
-rw-r--r--binaryview.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/binaryview.cpp b/binaryview.cpp
index 78b653a0..21a37bee 100644
--- a/binaryview.cpp
+++ b/binaryview.cpp
@@ -3914,27 +3914,33 @@ Ref<BinaryView> BinaryNinja::OpenView(const std::string& filename, bool updateAn
static const std::string sqlite_header = "SQLite format 3";
FILE* f = fopen(filename.c_str(), "rb");
+ // Unable to open file
if (f == nullptr)
return nullptr;
+
char header[0x20];
fread(header, 1, sqlite_header.size(), f);
fclose(f);
header[sqlite_header.size()] = 0;
+ // File is not a valid sqlite db
if (sqlite_header != header)
return nullptr;
Ref<FileMetadata> file = new FileMetadata(filename);
view = file->OpenDatabaseForConfiguration(filename);
- return OpenView(view, updateAnalysis, progress, options, true);
+ isDatabase = true;
}
else
{
// Open file, read raw contents
Ref<FileMetadata> file = new FileMetadata(filename);
view = new BinaryData(file, filename);
- return OpenView(view, updateAnalysis, progress, options, false);
}
+
+ if (!view)
+ return nullptr;
+ return OpenView(view, updateAnalysis, progress, options, isDatabase);
}