changeset 289:cc8ee701f190

pst_block_offset elements are unsigned; consistent usage of pst_malloc and pst_realloc
author Carl Byington <carl@five-ten-sg.com>
date Fri, 27 May 2011 11:36:49 -0700
parents fa7fc1ac6385
children fec37c150982
files regression/regression-tests.bash src/debug.c src/define.h src/libpst.c src/readpst.c
diffstat 5 files changed, 25 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/regression/regression-tests.bash	Fri May 27 09:50:24 2011 -0700
+++ b/regression/regression-tests.bash	Fri May 27 11:36:49 2011 -0700
@@ -65,13 +65,13 @@
             #$val ../src/readpst $jobs -te -r -D -cv -o output$n -d $ba.log $fn >$ba.err 2>&1
 
             ## normal recursive dump
-            $val ../src/readpst  -j 0 -r -cv -o output$n -d $ba.log $fn >$ba.err 2>&1
+            #$val ../src/readpst  -j 0 -r -cv -o output$n -d $ba.log $fn >$ba.err 2>&1
 
             ## separate mode with filename extensions
             #$val ../src/readpst $jobs     -r -e -D -cv -o output$n -d $ba.log $fn >$ba.err 2>&1
 
             ## separate mode where we decode all attachments to binary files
-            #$val ../src/readpst $jobs     -r -S -D -cv -o output$n -d $ba.log $fn >$ba.err 2>&1
+            $val ../src/readpst $jobs     -r -S -D -cv -o output$n -d $ba.log $fn >$ba.err 2>&1
 
             ## testing idblock
             #../src/getidblock -p $fn 0 >$ba.fulldump
--- a/src/debug.c	Fri May 27 09:50:24 2011 -0700
+++ b/src/debug.c	Fri May 27 11:36:49 2011 -0700
@@ -164,3 +164,12 @@
     return mem;
 }
 
+
+void *pst_realloc(void *ptr, size_t size) {
+    void *mem = realloc(ptr, size);
+    if (!mem) {
+        fprintf(stderr, "pst_realloc: Out Of memory [req: %ld]\n", (long)size);
+        exit(1);
+    }
+    return mem;
+}
--- a/src/define.h	Fri May 27 09:50:24 2011 -0700
+++ b/src/define.h	Fri May 27 11:36:49 2011 -0700
@@ -143,6 +143,7 @@
 void  pst_debug_hexdumper(FILE* out, const char* buf, size_t size, int cols, int delta);
 void  pst_debug_close(void);
 void* pst_malloc(size_t size);
+void *pst_realloc(void *ptr, size_t size);
 
 #define MESSAGEPRINT(...) pst_debug(__LINE__, __FILE__,  __VA_ARGS__)
 
--- a/src/libpst.c	Fri May 27 09:50:24 2011 -0700
+++ b/src/libpst.c	Fri May 27 11:36:49 2011 -0700
@@ -50,8 +50,8 @@
 
 
 typedef struct pst_block_offset {
-    int16_t from;
-    int16_t to;
+    uint16_t from;
+    uint16_t to;
 } pst_block_offset;
 
 
@@ -1869,7 +1869,7 @@
 
 // malloc space and copy the current item's data null terminated
 #define LIST_COPY(targ, type) {                                    \
-    targ = type realloc(targ, list->elements[x]->size+1);          \
+    targ = type pst_realloc(targ, list->elements[x]->size+1);      \
     memcpy(targ, list->elements[x]->data, list->elements[x]->size);\
     memset(((char*)targ)+list->elements[x]->size, 0, (size_t)1);   \
 }
@@ -2052,7 +2052,7 @@
         DEBUG_WARN(("src not 0x40 for filetime dst\n"));                    \
         DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size);    \
     }                                                                       \
-    targ = (FILETIME*) realloc(targ, sizeof(FILETIME));                     \
+    targ = (FILETIME*) pst_realloc(targ, sizeof(FILETIME));                 \
     memcpy(targ, list->elements[x]->data, list->elements[x]->size);         \
     LE32_CPU(targ->dwLowDateTime);                                          \
     LE32_CPU(targ->dwHighDateTime);                                         \
@@ -2083,7 +2083,7 @@
 #define LIST_COPY_BIN(targ) {                                       \
     targ.size = list->elements[x]->size;                            \
     if (targ.size) {                                                \
-        targ.data = (char*)realloc(targ.data, targ.size);           \
+        targ.data = (char*)pst_realloc(targ.data, targ.size);       \
         memcpy(targ.data, list->elements[x]->data, targ.size);      \
     }                                                               \
     else {                                                          \
@@ -2151,7 +2151,7 @@
                                 offset      = PST_LE_GET_INT32(list->elements[x]->data + p); p+=4;
                                 next_offset = (i == array_element_count) ? list->elements[x]->size : PST_LE_GET_INT32(list->elements[x]->data + p);;
                                 string_length = next_offset - offset;
-                                ef->value = malloc(string_length + 1);
+                                ef->value = pst_malloc(string_length + 1);
                                 memcpy(ef->value, list->elements[x]->data + offset, string_length);
                                 ef->value[string_length] = '\0';
                                 ef->field_name = strdup(list->elements[x]->extra);
@@ -4066,7 +4066,7 @@
 
     // raw append to a buffer
     if (h->buf) {
-        *(h->buf) = realloc(*(h->buf), size+z+1);
+        *(h->buf) = pst_realloc(*(h->buf), size+z+1);
         DEBUG_INFO(("appending read data of size %i onto main buffer from pos %i\n", z, size));
         memcpy(*(h->buf)+size, *buf, z);
 
@@ -4075,7 +4075,7 @@
         //
         if (h->base64_extra) {
             // include any bytes left over from the last encoding
-            *buf = (char*)realloc(*buf, z+h->base64_extra);
+            *buf = (char*)pst_realloc(*buf, z+h->base64_extra);
             memmove(*buf+h->base64_extra, *buf, z);
             memcpy(*buf, h->base64_extra_chars, h->base64_extra);
             z += h->base64_extra;
@@ -4217,7 +4217,7 @@
     else {
         x = strlen(str) + y - z + 1; // don't forget room for the NUL
         if (x > *buflen) {
-            *buf = (char*) realloc(*buf, x);
+            *buf = (char*)pst_realloc(*buf, x);
             *buflen = x;
         }
         a = str;
--- a/src/readpst.c	Fri May 27 09:50:24 2011 -0700
+++ b/src/readpst.c	Fri May 27 11:36:49 2011 -0700
@@ -742,7 +742,7 @@
         x = errno;
         DIE(("mk_kmail_dir: Cannot change to directory %s: %s\n", kmail_chdir, strerror(x)));
     }
-    dir = malloc(strlen(fname)+strlen(OUTPUT_KMAIL_DIR_TEMPLATE)+1);
+    dir = pst_malloc(strlen(fname)+strlen(OUTPUT_KMAIL_DIR_TEMPLATE)+1);
     sprintf(dir, OUTPUT_KMAIL_DIR_TEMPLATE, fname);
     check_filename(dir);
     if (D_MKDIR(dir)) {
@@ -751,17 +751,17 @@
             DIE(("mk_kmail_dir: Cannot create directory %s: %s\n", dir, strerror(x)));
         }
     }
-    kmail_chdir = realloc(kmail_chdir, strlen(dir)+1);
+    kmail_chdir = pst_realloc(kmail_chdir, strlen(dir)+1);
     strcpy(kmail_chdir, dir);
     free (dir);
 
     //we should remove any existing indexes created by KMail, cause they might be different now
-    index = malloc(strlen(fname)+strlen(KMAIL_INDEX)+1);
+    index = pst_malloc(strlen(fname)+strlen(KMAIL_INDEX)+1);
     sprintf(index, KMAIL_INDEX, fname);
     unlink(index);
     free(index);
 
-    out_name = malloc(strlen(fname)+strlen(OUTPUT_TEMPLATE)+1);
+    out_name = pst_malloc(strlen(fname)+strlen(OUTPUT_TEMPLATE)+1);
     sprintf(out_name, OUTPUT_TEMPLATE, fname);
     DEBUG_RET();
     return out_name;