Skip to content

Commit 00f03f1

Browse files
committed
gui: Prevent HexWidget data overwrite from changing the length of the buffer
1 parent b3821a5 commit 00f03f1

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

gui/qt/debugger/hexwidget.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,12 @@ void HexWidget::overwrite(int addr, char c) {
293293
m_modified[address] = m_modified[address] + 1;
294294
}
295295

296-
void HexWidget::overwrite(int addr, int len, const QByteArray &ba) {
296+
void HexWidget::overwrite(int addr, const QByteArray &ba) {
297297
int address = addr / 2;
298-
stack_entry_t entry{addr, m_data.mid(address, len)};
299-
m_stack.push(entry);
300-
m_data.replace(address, len, ba);
298+
stack_entry_t entry{addr, m_data.mid(address, ba.size())};
299+
int len = entry.ba.size();
300+
m_stack.push(std::move(entry));
301+
m_data.replace(address, len, QByteArray::fromRawData(ba.constData(), len));
301302
for (int i = address; i < address + len; i++) {
302303
m_modified[i] = m_modified[i] + 1;
303304
}
@@ -486,7 +487,7 @@ void HexWidget::keyPressEvent(QKeyEvent *event) {
486487
if (!m_asciiEdit) {
487488
ba = QByteArray::fromHex(ba);
488489
}
489-
overwrite(addr, ba.size(), ba);
490+
overwrite(addr, ba);
490491
setCursorOffset(addr + ba.size() * 2);
491492
} else
492493
if (event->matches(QKeySequence::Delete)) {

gui/qt/debugger/hexwidget.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ private slots:
5858
void setSelection(int addr);
5959
void resetSelection() { m_selectStart = m_selectEnd = -1; }
6060
bool isSelected() const { return m_selectStart != -1; }
61-
void setSelected(char n) { overwrite(m_selectStart * 2, m_selectLen, QByteArray(m_selectLen, n)); }
61+
void setSelected(char n) { overwrite(m_selectStart * 2, QByteArray(m_selectLen, n)); }
6262
void overwrite(int pos, char c);
63-
void overwrite(int pos, int len, const QByteArray &ba);
63+
void overwrite(int pos, const QByteArray &ba);
6464
int getPosition(QPoint posa, bool allow = true);
6565

6666
typedef struct {

0 commit comments

Comments
 (0)