From ee24db11e157ba87fe3a8cb127202c89e54d6c51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 26 Feb 2004 01:59:42 +0000 Subject: [PATCH] Added some argument bound checks in Replace() and SetViewOffset(). Replace(), Insert(), and Remove() now locks the editor themselves. ReplaceChange::Normalize() corrected the size for the right reason in a wrong way. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6741 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/diskprobe/DataEditor.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/apps/diskprobe/DataEditor.cpp b/src/apps/diskprobe/DataEditor.cpp index 10b513c1a6..310a21f147 100644 --- a/src/apps/diskprobe/DataEditor.cpp +++ b/src/apps/diskprobe/DataEditor.cpp @@ -90,7 +90,7 @@ ReplaceChange::Normalize(off_t bufferOffset, size_t bufferSize, off_t &offset, } if (offset + size > bufferOffset + bufferSize) - size = offset - bufferOffset + offset; + size = bufferOffset + bufferSize - offset; } @@ -98,7 +98,7 @@ void ReplaceChange::Apply(off_t bufferOffset, uint8 *buffer, size_t bufferSize) { // is it in our range? - if (fOffset - bufferOffset > bufferSize || fOffset + fSize < bufferOffset) + if (fOffset > bufferOffset + bufferSize || fOffset + fSize < bufferOffset) return; // don't change anything outside the supplied buffer @@ -318,8 +318,12 @@ DataEditor::AddChange(DataChange *change) status_t DataEditor::Replace(off_t offset, const uint8 *data, size_t length) { - if (!IsLocked()) - debugger("DataEditor: view not locked"); + BAutolock locker(this); + + if (offset >= fSize) + return B_BAD_VALUE; + if (offset + length > fSize) + length = fSize - offset; if (fNeedsUpdate) { status_t status = Update(); @@ -337,8 +341,7 @@ DataEditor::Replace(off_t offset, const uint8 *data, size_t length) status_t DataEditor::Remove(off_t offset, off_t length) { - if (!IsLocked()) - debugger("DataEditor: view not locked"); + BAutolock locker(this); // not yet implemented @@ -349,8 +352,7 @@ DataEditor::Remove(off_t offset, off_t length) status_t DataEditor::Insert(off_t offset, const uint8 *text, size_t length) { - if (!IsLocked()) - debugger("DataEditor: view not locked"); + BAutolock locker(this); // not yet implemented @@ -491,6 +493,9 @@ DataEditor::SetViewOffset(off_t offset) return status; } + if (offset < 0 || offset > fSize) + return B_BAD_VALUE; + fRealViewOffset = (offset / fBlockSize) * fBlockSize; fViewOffset = offset; fNeedsUpdate = true;