From b7c3929d5e15424f4120ddd887722a3fe7af7322 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergi=20=C3=80lvarez=20i=20Capilla?= Date: Sun, 9 Apr 2017 19:09:52 +0200 Subject: [PATCH] Fix null deref (#101) * Fix null deref when QStringList is empty * Indent memory widget --- src/widgets/memwidget/memorywidget.cpp | 107 +++++++++++++------------ 1 file changed, 55 insertions(+), 52 deletions(-) diff --git a/src/widgets/memwidget/memorywidget.cpp b/src/widgets/memwidget/memorywidget.cpp index bf8e4d82..b8cff5b1 100644 --- a/src/widgets/memwidget/memorywidget.cpp +++ b/src/widgets/memwidget/memorywidget.cpp @@ -461,9 +461,12 @@ void MemoryWidget::refreshDisasm(QString off = "") { QTextCursor tc = this->disasTextEdit->textCursor(); tc.select( QTextCursor::LineUnderCursor ); QString lastline = tc.selectedText(); - QString ele = lastline.split(" ", QString::SkipEmptyParts)[0]; - if (ele.contains("0x")) { - this->main->core->cmd("s " + ele); + QStringList elements = lastline.split(" ", QString::SkipEmptyParts); + if (elements.length() > 0) { + QString ele = elements[0]; + if (ele.contains("0x")) { + this->main->core->cmd("s " + ele); + } } } @@ -959,7 +962,7 @@ void MemoryWidget::on_actionSettings_menu_1_triggered() { bool ok = true; - // QFont font = QFont("Monospace", 8); + // QFont font = QFont("Monospace", 8); QFont font = QFontDialog::getFont( &ok, ui->disasTextEdit_2->font(), this); setFonts (font); @@ -1566,54 +1569,54 @@ void MemoryWidget::on_previewToolButton_2_clicked() } bool MemoryWidget::eventFilter(QObject *obj, QEvent *event) { - if (event->type() == QEvent::Resize && obj == this && this->isVisible()) { - if (this->main->responsive) { - QResizeEvent *resizeEvent = static_cast(event); - //qDebug("Dock Resized (New Size) - Width: %d Height: %d", - // resizeEvent->size().width(), - // resizeEvent->size().height()); - if (resizeEvent->size().width() <= 1150) { - ui->frame_3->setVisible(false); - ui->memPreviewTab->setVisible(false); - ui->previewToolButton_2->setChecked(false); - if (resizeEvent->size().width() <= 950) { - ui->memSideTabWidget_2->hide(); - ui->hexSideTab_2->hide(); - ui->memSideToolButton->setChecked(true); - } else { - ui->memSideTabWidget_2->show(); - ui->hexSideTab_2->show(); - ui->memSideToolButton->setChecked(false); - } - } else { - ui->frame_3->setVisible(true); - ui->memPreviewTab->setVisible(true); - ui->previewToolButton_2->setChecked(true); - } - } - } else if ((obj == ui->disasTextEdit_2 || obj==ui->disasTextEdit_2->viewport()) && event->type() == QEvent::MouseButtonDblClick) { - QMouseEvent *mouseEvent = static_cast(event); - //qDebug()<x()).arg(mouseEvent->y()); - QTextCursor cursor = ui->disasTextEdit_2->cursorForPosition( QPoint(mouseEvent->x(), mouseEvent->y()) ); - cursor.select( QTextCursor::LineUnderCursor ); - QString lastline = cursor.selectedText(); - QString ele = lastline.split(" ", QString::SkipEmptyParts)[0]; - if (ele.contains("0x")) { - QString jump = ""; - jump = this->main->core->getOffsetJump(ele); - if (jump != "") { - if (jump.contains("0x")) { - QString fcn = this->main->core->cmdFunctionAt(jump); - if (fcn != "") { - this->main->seek(jump.trimmed(), fcn); - } - } else { - this->main->seek(this->main->core->cmd("?v " + jump), jump); - } - } - } - } - return QDockWidget::eventFilter(obj, event); + if (event->type() == QEvent::Resize && obj == this && this->isVisible()) { + if (this->main->responsive) { + QResizeEvent *resizeEvent = static_cast(event); + //qDebug("Dock Resized (New Size) - Width: %d Height: %d", + // resizeEvent->size().width(), + // resizeEvent->size().height()); + if (resizeEvent->size().width() <= 1150) { + ui->frame_3->setVisible(false); + ui->memPreviewTab->setVisible(false); + ui->previewToolButton_2->setChecked(false); + if (resizeEvent->size().width() <= 950) { + ui->memSideTabWidget_2->hide(); + ui->hexSideTab_2->hide(); + ui->memSideToolButton->setChecked(true); + } else { + ui->memSideTabWidget_2->show(); + ui->hexSideTab_2->show(); + ui->memSideToolButton->setChecked(false); + } + } else { + ui->frame_3->setVisible(true); + ui->memPreviewTab->setVisible(true); + ui->previewToolButton_2->setChecked(true); + } + } + } else if ((obj == ui->disasTextEdit_2 || obj==ui->disasTextEdit_2->viewport()) && event->type() == QEvent::MouseButtonDblClick) { + QMouseEvent *mouseEvent = static_cast(event); + //qDebug()<x()).arg(mouseEvent->y()); + QTextCursor cursor = ui->disasTextEdit_2->cursorForPosition( QPoint(mouseEvent->x(), mouseEvent->y()) ); + cursor.select( QTextCursor::LineUnderCursor ); + QString lastline = cursor.selectedText(); + QString ele = lastline.split(" ", QString::SkipEmptyParts)[0]; + if (ele.contains("0x")) { + QString jump = ""; + jump = this->main->core->getOffsetJump(ele); + if (jump != "") { + if (jump.contains("0x")) { + QString fcn = this->main->core->cmdFunctionAt(jump); + if (fcn != "") { + this->main->seek(jump.trimmed(), fcn); + } + } else { + this->main->seek(this->main->core->cmd("?v " + jump), jump); + } + } + } + } + return QDockWidget::eventFilter(obj, event); } void MemoryWidget::on_actionXRefs_triggered()