mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-18 19:06:10 +00:00
Fix many null derefs when opening no file
This commit is contained in:
parent
06c8f15ce0
commit
cb26142398
@ -644,6 +644,10 @@ bool CutterCore::loadFile(QString path, ut64 baddr, ut64 mapaddr, int perms, int
|
||||
|
||||
bool CutterCore::tryFile(QString path, bool rw)
|
||||
{
|
||||
if (path.isEmpty()) {
|
||||
// opening no file is always possible
|
||||
return true;
|
||||
}
|
||||
CORE_LOCK();
|
||||
RzCoreFile *cf;
|
||||
int flags = RZ_PERM_R;
|
||||
@ -3484,6 +3488,9 @@ QList<EntrypointDescription> CutterCore::getAllEntrypoint()
|
||||
{
|
||||
CORE_LOCK();
|
||||
RzBinFile *bf = rz_bin_cur(core->bin);
|
||||
if (!bf) {
|
||||
return {};
|
||||
}
|
||||
bool va = core->io->va || core->bin->is_debugger;
|
||||
ut64 baddr = rz_bin_get_baddr(core->bin);
|
||||
ut64 laddr = rz_bin_get_laddr(core->bin);
|
||||
@ -4321,14 +4328,15 @@ void CutterCore::commitWriteCache()
|
||||
// Temporarily disable cache mode
|
||||
TempConfig tempConfig;
|
||||
tempConfig.set("io.cache", false);
|
||||
if (!isWriteModeEnabled()) {
|
||||
rz_core_io_file_reopen(core, core->io->desc->fd, RZ_PERM_RW);
|
||||
rz_io_cache_commit(core->io, 0, UT64_MAX);
|
||||
rz_core_block_read(core);
|
||||
rz_core_io_file_open(core, core->io->desc->fd);
|
||||
} else {
|
||||
auto desc = core->io->desc;
|
||||
bool reopen = !isWriteModeEnabled() && desc;
|
||||
if (reopen) {
|
||||
rz_core_io_file_reopen(core, desc->fd, RZ_PERM_RW);
|
||||
}
|
||||
rz_io_cache_commit(core->io, 0, UT64_MAX);
|
||||
rz_core_block_read(core);
|
||||
if (reopen) {
|
||||
rz_core_io_file_open(core, desc->fd);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4350,13 +4358,16 @@ void CutterCore::setWriteMode(bool enabled)
|
||||
|
||||
CORE_LOCK();
|
||||
// Change from read-only to write-mode
|
||||
RzIODesc *desc = core->io->desc;
|
||||
if (desc) {
|
||||
if (enabled) {
|
||||
if (!writeModeState) {
|
||||
rz_core_io_file_reopen(core, core->io->desc->fd, RZ_PERM_RW);
|
||||
rz_core_io_file_reopen(core, desc->fd, RZ_PERM_RW);
|
||||
}
|
||||
} else {
|
||||
// Change from write-mode to read-only
|
||||
rz_core_io_file_open(core, core->io->desc->fd);
|
||||
rz_core_io_file_open(core, desc->fd);
|
||||
}
|
||||
}
|
||||
// Disable cache mode because we specifically set write or
|
||||
// read-only modes.
|
||||
|
@ -63,9 +63,9 @@ void Dashboard::updateContents()
|
||||
setPlainText(ui->subsysEdit, binInfo ? binInfo->subsystem : "");
|
||||
setPlainText(ui->compilerEdit, binInfo ? binInfo->compiler : "");
|
||||
setPlainText(ui->bitsEdit, binInfo ? QString::number(binInfo->bits) : "");
|
||||
setPlainText(ui->baddrEdit, binInfo ? RzAddressString(rz_bin_file_get_baddr(bf)) : "");
|
||||
setPlainText(ui->sizeEdit, binInfo ? qhelpers::formatBytecount(bf->size) : "");
|
||||
setPlainText(ui->fdEdit, binInfo ? QString::number(bf->fd) : "");
|
||||
setPlainText(ui->baddrEdit, bf ? RzAddressString(rz_bin_file_get_baddr(bf)) : "");
|
||||
setPlainText(ui->sizeEdit, bf ? qhelpers::formatBytecount(bf->size) : "");
|
||||
setPlainText(ui->fdEdit, bf ? QString::number(bf->fd) : "");
|
||||
|
||||
// Setting the value of "Endianness"
|
||||
const char *endian = binInfo ? (binInfo->big_endian ? "BE" : "LE") : "";
|
||||
@ -78,7 +78,7 @@ void Dashboard::updateContents()
|
||||
int static_value = rz_bin_is_static(core->bin);
|
||||
setPlainText(ui->staticEdit, tr(setBoolText(static_value)));
|
||||
|
||||
RzList *hashes = rz_bin_file_compute_hashes(core->bin, bf, UT64_MAX);
|
||||
RzList *hashes = bf ? rz_bin_file_compute_hashes(core->bin, bf, UT64_MAX) : nullptr;
|
||||
|
||||
// Delete hashesWidget if it isn't null to avoid duplicate components
|
||||
if (hashesWidget) {
|
||||
@ -135,7 +135,7 @@ void Dashboard::updateContents()
|
||||
}
|
||||
}
|
||||
|
||||
const RzList *libs = rz_bin_object_get_libs(bf->o);
|
||||
const RzList *libs = bf ? rz_bin_object_get_libs(bf->o) : nullptr;
|
||||
if (libs) {
|
||||
for (const auto &lib : CutterRzList<char>(libs)) {
|
||||
auto *label = new QLabel(this);
|
||||
|
Loading…
Reference in New Issue
Block a user