about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2011-05-02 15:29:29 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2011-05-02 15:29:29 +0000
commitdcfa7227782186acb17d846b5b37d1b8f014a4fb (patch)
treea2e208c44e65ed2510ffd929b0c3621c631069d7
parent6259689f2573ab5e1d70b4cbc78533a0da35be88 (diff)
downloadnetpbm-mirror-dcfa7227782186acb17d846b5b37d1b8f014a4fb.tar.gz
netpbm-mirror-dcfa7227782186acb17d846b5b37d1b8f014a4fb.tar.xz
netpbm-mirror-dcfa7227782186acb17d846b5b37d1b8f014a4fb.zip
fix crash on corrupted input
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1486 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r--converter/other/srf.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/converter/other/srf.c b/converter/other/srf.c
index ce9ae604..508d40a0 100644
--- a/converter/other/srf.c
+++ b/converter/other/srf.c
@@ -43,21 +43,24 @@ static bool
 readPstring(FILE *               const ifP,
             struct srf_pstring * const pstringP) {
 
-    bool retval;
     size_t bytesRead;
 
     pm_readlittlelong2u(ifP, &pstringP->len);
 
-    MALLOCARRAY_NOFAIL(pstringP->val, pstringP->len + 1);
+    MALLOCARRAY(pstringP->val, pstringP->len + 1);
+
+    if (!pstringP->val)
+        pm_error("Failed to allocate buffer to read %u-byte pstring",
+                 pstringP->len);
 
     bytesRead = fread(pstringP->val, 1, pstringP->len, ifP);
     if (bytesRead != pstringP->len)
-        retval = false;
-    else {
-        pstringP->val[pstringP->len] = '\0';
-        retval = true;
-    }        
-    return retval;
+        pm_error("Failed to read pstring.  Requested %u bytes, got %u",
+                 (unsigned)pstringP->len,  (unsigned)bytesRead);
+
+    pstringP->val[pstringP->len] = '\0';
+
+    return true;
 }