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