From 01ea7350f8728781e60850fad9c87e04bf219bf0 Mon Sep 17 00:00:00 2001 From: Mark McLoughlin Date: Tue, 21 Sep 2004 16:11:26 +0000 Subject: [PATCH] check gnome_vfs_foo return values. Fixes crashes with gnome-vfs' http 2004-09-20 Mark McLoughlin * xpdf/GnomeVFSStream.cc (reset, fillBuf): check gnome_vfs_foo return values. Fixes crashes with gnome-vfs' http method. Bug #153159, #151364, Red Hat Bug #132469, half of Debian Bug #268873. --- pdf/xpdf/GnomeVFSStream.cc | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/pdf/xpdf/GnomeVFSStream.cc b/pdf/xpdf/GnomeVFSStream.cc index 324e4088..4ff30a5f 100644 --- a/pdf/xpdf/GnomeVFSStream.cc +++ b/pdf/xpdf/GnomeVFSStream.cc @@ -47,9 +47,10 @@ Stream *GnomeVFSStream::makeSubStream(Guint startA, GBool limitedA, void GnomeVFSStream::reset() { GnomeVFSFileSize offsetReturn; - gnome_vfs_tell(handle, &offsetReturn); - savePos = (Guint)offsetReturn; - saved = gTrue; + if (gnome_vfs_tell(handle, &offsetReturn) == GNOME_VFS_OK) { + savePos = (Guint)offsetReturn; + saved = gTrue; + } gnome_vfs_seek(handle, GNOME_VFS_SEEK_START, start); bufPtr = bufEnd = buf; bufPos = start; @@ -83,7 +84,9 @@ GBool GnomeVFSStream::fillBuf() { } else { n = gnomeVFSStreamBufSize; } - gnome_vfs_read(handle, buf, n, &bytesRead); + if (gnome_vfs_read(handle, buf, n, &bytesRead) != GNOME_VFS_OK) { + return gFalse; + } bufEnd = buf + bytesRead; if (bufPtr >= bufEnd) { return gFalse; @@ -99,21 +102,22 @@ GBool GnomeVFSStream::fillBuf() { } void GnomeVFSStream::setPos(Guint pos, int dir) { - Guint size; - if (dir >= 0) { - gnome_vfs_seek(handle, GNOME_VFS_SEEK_START, pos); - bufPos = pos; + if (gnome_vfs_seek(handle, GNOME_VFS_SEEK_START, pos) == GNOME_VFS_OK) { + bufPos = pos; + } } else { GnomeVFSFileSize offsetReturn; - gnome_vfs_seek(handle, GNOME_VFS_SEEK_END, 0); - gnome_vfs_tell(handle, &offsetReturn); - size = (Guint)offsetReturn; - if (pos > size) - pos = (Guint)size; - gnome_vfs_seek(handle, GNOME_VFS_SEEK_END, -(int)pos); - gnome_vfs_tell(handle, &offsetReturn); - bufPos = (Guint)offsetReturn; + if (gnome_vfs_seek(handle, GNOME_VFS_SEEK_END, 0) == GNOME_VFS_OK && + gnome_vfs_tell(handle, &offsetReturn) == GNOME_VFS_OK) { + bufPos = (Guint)offsetReturn; + if (pos > bufPos) + pos = (Guint)bufPos; + if (gnome_vfs_seek(handle, GNOME_VFS_SEEK_END, -(int)pos) == GNOME_VFS_OK && + gnome_vfs_tell(handle, &offsetReturn) == GNOME_VFS_OK) { + bufPos = (Guint)offsetReturn; + } + } } bufPtr = bufEnd = buf; } -- 2.43.5