diff options
author | Ed Avis <eda@waniasset.com> | 2008-03-22 13:55:59 +0100 |
---|---|---|
committer | Albert Astals Cid <aacid@kde.org> | 2008-03-22 13:55:59 +0100 |
commit | 23b6475463f8973b5ac83bb21a6b7b6000cc435b (patch) | |
tree | efcd05d96d9534d85bd875ac52040c1412809c1c | |
parent | b33bb282e45cf1a083cfbb13603ac465d386c28d (diff) |
Check for fseek return values
-rw-r--r-- | fofi/FoFiBase.cc | 14 | ||||
-rw-r--r-- | poppler/GfxFont.cc | 12 |
2 files changed, 22 insertions, 4 deletions
diff --git a/fofi/FoFiBase.cc b/fofi/FoFiBase.cc index ef8992a0..1174f3af 100644 --- a/fofi/FoFiBase.cc +++ b/fofi/FoFiBase.cc @@ -14,6 +14,7 @@ #include <stdio.h> #include "goo/gmem.h" +#include "Error.h" #include "FoFiBase.h" //------------------------------------------------------------------------ @@ -38,11 +39,20 @@ char *FoFiBase::readFile(char *fileName, int *fileLen) { int n; if (!(f = fopen(fileName, "rb"))) { + error(-1, "Cannot open '%s'", fileName); + return NULL; + } + if (fseek(f, 0, SEEK_END) != 0) { + error(-1, "Cannot seek to end of '%s'", fileName); + fclose(f); return NULL; } - fseek(f, 0, SEEK_END); n = (int)ftell(f); - fseek(f, 0, SEEK_SET); + if (fseek(f, 0, SEEK_SET) != 0) { + error(-1, "Cannot seek to start of '%s'", fileName); + fclose(f); + return NULL; + } buf = (char *)gmalloc(n); if ((int)fread(buf, 1, n, f) != n) { gfree(buf); diff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc index 655e2599..d4c21706 100644 --- a/poppler/GfxFont.cc +++ b/poppler/GfxFont.cc @@ -408,9 +408,17 @@ char *GfxFont::readExtFontFile(int *len) { error(-1, "External font file '%s' vanished", extFontFile->getCString()); return NULL; } - fseek(f, 0, SEEK_END); + if (fseek(f, 0, SEEK_END) != 0) { + error(-1, "Cannot seek to end of '%s'", extFontFile->getCString()); + fclose(f); + return NULL; + } *len = (int)ftell(f); - fseek(f, 0, SEEK_SET); + if (fseek(f, 0, SEEK_SET) != 0) { + error(-1, "Cannot seek to start of '%s'", extFontFile->getCString()); + fclose(f); + return NULL; + } buf = (char *)gmalloc(*len); if ((int)fread(buf, 1, *len, f) != *len) { error(-1, "Error reading external font file '%s'", |