From 7170b90c2ad8c3014c69f12a0192e7464336f492 Mon Sep 17 00:00:00 2001 From: Pixel Date: Tue, 2 Jun 2009 00:07:39 +0000 Subject: Protecting Buffers against erratic seeks. --- lib/Buffer.cc | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib') diff --git a/lib/Buffer.cc b/lib/Buffer.cc index 68ecb9e..473da62 100644 --- a/lib/Buffer.cc +++ b/lib/Buffer.cc @@ -181,9 +181,11 @@ bool Buffer::CanSeek() const { } off_t Buffer::seek(off_t off, int wheel) throw (GeneralException) { + size_t old_ptr; if (!seekable) { throw GeneralException("This buffer is a fifo, thus is not seekable"); } + old_ptr = ptr; switch (wheel) { case SEEK_SET: ptr = off; @@ -195,6 +197,10 @@ off_t Buffer::seek(off_t off, int wheel) throw (GeneralException) { ptr = realsiz + off; break; } + if (ptr < 0) { + ptr = old_ptr; + throw GeneralException("Can't seek a Buffer before its start.") + } operator[](ptr); return ptr; } -- cgit v1.2.3