comparison src/libpst.c @ 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 0f0ccd29b0d7
children 8b3a827b71f4
comparison
equal deleted inserted replaced
288:fa7fc1ac6385 289:cc8ee701f190
48 48
49 #define PST_SIGNATURE 0x4E444221 49 #define PST_SIGNATURE 0x4E444221
50 50
51 51
52 typedef struct pst_block_offset { 52 typedef struct pst_block_offset {
53 int16_t from; 53 uint16_t from;
54 int16_t to; 54 uint16_t to;
55 } pst_block_offset; 55 } pst_block_offset;
56 56
57 57
58 typedef struct pst_block_offset_pointer { 58 typedef struct pst_block_offset_pointer {
59 char *from; 59 char *from;
1867 #define MALLOC_JOURNAL(x) { if (!x->journal) { x->journal = (pst_item_journal*) pst_malloc(sizeof(pst_item_journal)); memset(x->journal, 0, sizeof(pst_item_journal) );} } 1867 #define MALLOC_JOURNAL(x) { if (!x->journal) { x->journal = (pst_item_journal*) pst_malloc(sizeof(pst_item_journal)); memset(x->journal, 0, sizeof(pst_item_journal) );} }
1868 #define MALLOC_APPOINTMENT(x) { if (!x->appointment) { x->appointment = (pst_item_appointment*) pst_malloc(sizeof(pst_item_appointment)); memset(x->appointment, 0, sizeof(pst_item_appointment) );} } 1868 #define MALLOC_APPOINTMENT(x) { if (!x->appointment) { x->appointment = (pst_item_appointment*) pst_malloc(sizeof(pst_item_appointment)); memset(x->appointment, 0, sizeof(pst_item_appointment) );} }
1869 1869
1870 // malloc space and copy the current item's data null terminated 1870 // malloc space and copy the current item's data null terminated
1871 #define LIST_COPY(targ, type) { \ 1871 #define LIST_COPY(targ, type) { \
1872 targ = type realloc(targ, list->elements[x]->size+1); \ 1872 targ = type pst_realloc(targ, list->elements[x]->size+1); \
1873 memcpy(targ, list->elements[x]->data, list->elements[x]->size);\ 1873 memcpy(targ, list->elements[x]->data, list->elements[x]->size);\
1874 memset(((char*)targ)+list->elements[x]->size, 0, (size_t)1); \ 1874 memset(((char*)targ)+list->elements[x]->size, 0, (size_t)1); \
1875 } 1875 }
1876 1876
1877 #define LIST_COPY_CSTR(targ) { \ 1877 #define LIST_COPY_CSTR(targ) { \
2050 #define LIST_COPY_TIME(label, targ) { \ 2050 #define LIST_COPY_TIME(label, targ) { \
2051 if (list->elements[x]->type != 0x40) { \ 2051 if (list->elements[x]->type != 0x40) { \
2052 DEBUG_WARN(("src not 0x40 for filetime dst\n")); \ 2052 DEBUG_WARN(("src not 0x40 for filetime dst\n")); \
2053 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); \ 2053 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); \
2054 } \ 2054 } \
2055 targ = (FILETIME*) realloc(targ, sizeof(FILETIME)); \ 2055 targ = (FILETIME*) pst_realloc(targ, sizeof(FILETIME)); \
2056 memcpy(targ, list->elements[x]->data, list->elements[x]->size); \ 2056 memcpy(targ, list->elements[x]->data, list->elements[x]->size); \
2057 LE32_CPU(targ->dwLowDateTime); \ 2057 LE32_CPU(targ->dwLowDateTime); \
2058 LE32_CPU(targ->dwHighDateTime); \ 2058 LE32_CPU(targ->dwHighDateTime); \
2059 DEBUG_INFO((label" - %s", pst_fileTimeToAscii(targ, time_buffer))); \ 2059 DEBUG_INFO((label" - %s", pst_fileTimeToAscii(targ, time_buffer))); \
2060 } 2060 }
2081 2081
2082 // malloc space and copy the current item's data and size 2082 // malloc space and copy the current item's data and size
2083 #define LIST_COPY_BIN(targ) { \ 2083 #define LIST_COPY_BIN(targ) { \
2084 targ.size = list->elements[x]->size; \ 2084 targ.size = list->elements[x]->size; \
2085 if (targ.size) { \ 2085 if (targ.size) { \
2086 targ.data = (char*)realloc(targ.data, targ.size); \ 2086 targ.data = (char*)pst_realloc(targ.data, targ.size); \
2087 memcpy(targ.data, list->elements[x]->data, targ.size); \ 2087 memcpy(targ.data, list->elements[x]->data, targ.size); \
2088 } \ 2088 } \
2089 else { \ 2089 else { \
2090 SAFE_FREE_BIN(targ); \ 2090 SAFE_FREE_BIN(targ); \
2091 targ.data = NULL; \ 2091 targ.data = NULL; \
2149 pst_item_extra_field *ef = (pst_item_extra_field*) pst_malloc(sizeof(pst_item_extra_field)); 2149 pst_item_extra_field *ef = (pst_item_extra_field*) pst_malloc(sizeof(pst_item_extra_field));
2150 memset(ef, 0, sizeof(pst_item_extra_field)); 2150 memset(ef, 0, sizeof(pst_item_extra_field));
2151 offset = PST_LE_GET_INT32(list->elements[x]->data + p); p+=4; 2151 offset = PST_LE_GET_INT32(list->elements[x]->data + p); p+=4;
2152 next_offset = (i == array_element_count) ? list->elements[x]->size : PST_LE_GET_INT32(list->elements[x]->data + p);; 2152 next_offset = (i == array_element_count) ? list->elements[x]->size : PST_LE_GET_INT32(list->elements[x]->data + p);;
2153 string_length = next_offset - offset; 2153 string_length = next_offset - offset;
2154 ef->value = malloc(string_length + 1); 2154 ef->value = pst_malloc(string_length + 1);
2155 memcpy(ef->value, list->elements[x]->data + offset, string_length); 2155 memcpy(ef->value, list->elements[x]->data + offset, string_length);
2156 ef->value[string_length] = '\0'; 2156 ef->value[string_length] = '\0';
2157 ef->field_name = strdup(list->elements[x]->extra); 2157 ef->field_name = strdup(list->elements[x]->extra);
2158 ef->next = item->extra_fields; 2158 ef->next = item->extra_fields;
2159 item->extra_fields = ef; 2159 item->extra_fields = ef;
4064 char *t; 4064 char *t;
4065 DEBUG_ENT("pst_append_holder"); 4065 DEBUG_ENT("pst_append_holder");
4066 4066
4067 // raw append to a buffer 4067 // raw append to a buffer
4068 if (h->buf) { 4068 if (h->buf) {
4069 *(h->buf) = realloc(*(h->buf), size+z+1); 4069 *(h->buf) = pst_realloc(*(h->buf), size+z+1);
4070 DEBUG_INFO(("appending read data of size %i onto main buffer from pos %i\n", z, size)); 4070 DEBUG_INFO(("appending read data of size %i onto main buffer from pos %i\n", z, size));
4071 memcpy(*(h->buf)+size, *buf, z); 4071 memcpy(*(h->buf)+size, *buf, z);
4072 4072
4073 // base64 encoding to a file 4073 // base64 encoding to a file
4074 } else if ((h->base64 == 1) && h->fp) { 4074 } else if ((h->base64 == 1) && h->fp) {
4075 // 4075 //
4076 if (h->base64_extra) { 4076 if (h->base64_extra) {
4077 // include any bytes left over from the last encoding 4077 // include any bytes left over from the last encoding
4078 *buf = (char*)realloc(*buf, z+h->base64_extra); 4078 *buf = (char*)pst_realloc(*buf, z+h->base64_extra);
4079 memmove(*buf+h->base64_extra, *buf, z); 4079 memmove(*buf+h->base64_extra, *buf, z);
4080 memcpy(*buf, h->base64_extra_chars, h->base64_extra); 4080 memcpy(*buf, h->base64_extra_chars, h->base64_extra);
4081 z += h->base64_extra; 4081 z += h->base64_extra;
4082 } 4082 }
4083 4083
4215 // there isn't any extra space required 4215 // there isn't any extra space required
4216 ret = str; 4216 ret = str;
4217 else { 4217 else {
4218 x = strlen(str) + y - z + 1; // don't forget room for the NUL 4218 x = strlen(str) + y - z + 1; // don't forget room for the NUL
4219 if (x > *buflen) { 4219 if (x > *buflen) {
4220 *buf = (char*) realloc(*buf, x); 4220 *buf = (char*)pst_realloc(*buf, x);
4221 *buflen = x; 4221 *buflen = x;
4222 } 4222 }
4223 a = str; 4223 a = str;
4224 b = *buf; 4224 b = *buf;
4225 while (*a != '\0') { 4225 while (*a != '\0') {