comparison src/libpst.c @ 47:5fb8d997feed

more fixes for 64 bit format
author carl
date Sun, 13 Jan 2008 12:55:59 -0800
parents b2a7f2e0926a
children f66078abed38
comparison
equal deleted inserted replaced
46:b2a7f2e0926a 47:5fb8d997feed
453 memcpy(&tint, &(headerbuffer[xattrib.extended]), sizeof(tint)); 453 memcpy(&tint, &(headerbuffer[xattrib.extended]), sizeof(tint));
454 LE32_CPU(tint); 454 LE32_CPU(tint);
455 wt = (char*) xmalloc((size_t)(tint+2)); // plus 2 for a uni-code zero 455 wt = (char*) xmalloc((size_t)(tint+2)); // plus 2 for a uni-code zero
456 memset(wt, 0, (size_t)(tint+2)); 456 memset(wt, 0, (size_t)(tint+2));
457 memcpy(wt, &(headerbuffer[xattrib.extended+sizeof(tint)]), (size_t)tint); 457 memcpy(wt, &(headerbuffer[xattrib.extended+sizeof(tint)]), (size_t)tint);
458 ptr->data = pst_wide_to_single(wt, tint); 458 ptr->data = pst_wide_to_single(wt, (size_t)tint);
459 free(wt); 459 free(wt);
460 DEBUG_INDEX(("Read string (converted from UTF-16): %s\n", ptr->data)); 460 DEBUG_INDEX(("Read string (converted from UTF-16): %s\n", ptr->data));
461 } else { 461 } else {
462 DEBUG_INDEX(("Cannot read outside of buffer [%i !< %i]\n", xattrib.extended, hsize)); 462 DEBUG_INDEX(("Cannot read outside of buffer [%i !< %i]\n", xattrib.extended, hsize));
463 } 463 }
1261 int32_t x; 1261 int32_t x;
1262 int num_recs; 1262 int num_recs;
1263 int count_rec; 1263 int count_rec;
1264 int32_t num_list; 1264 int32_t num_list;
1265 int32_t cur_list; 1265 int32_t cur_list;
1266 int32_t block_type; 1266 int block_type;
1267 uint32_t rec_size = 0; 1267 uint32_t rec_size = 0;
1268 uint32_t ind_ptr; 1268 uint32_t ind_ptr;
1269 unsigned char* list_start; 1269 unsigned char* list_start;
1270 unsigned char* fr_ptr; 1270 unsigned char* fr_ptr;
1271 unsigned char* to_ptr; 1271 unsigned char* to_ptr;
1398 DEBUG_RET(); 1398 DEBUG_RET();
1399 return NULL; 1399 return NULL;
1400 } 1400 }
1401 1401
1402 rec_size = seven_c_blk.rec_size; 1402 rec_size = seven_c_blk.rec_size;
1403 num_list = seven_c_blk.item_count; 1403 num_list = (int32_t)(unsigned)seven_c_blk.item_count;
1404 1404
1405 if (pst_getBlockOffsetPointer(pf, i2_head, buf, read_size, ind_ptr, seven_c_blk.b_five_offset, &block_offset4)) { 1405 if (pst_getBlockOffsetPointer(pf, i2_head, buf, read_size, ind_ptr, seven_c_blk.b_five_offset, &block_offset4)) {
1406 DEBUG_WARN(("internal error (7c.b5 offset %#x) in reading block id %#x\n", seven_c_blk.b_five_offset, block_id)); 1406 DEBUG_WARN(("internal error (7c.b5 offset %#x) in reading block id %#x\n", seven_c_blk.b_five_offset, block_id));
1407 freeall(buf, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); 1407 freeall(buf, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7);
1408 DEBUG_RET(); 1408 DEBUG_RET();
1469 na_head = na_ptr; 1469 na_head = na_ptr;
1470 // allocate an array of count num_recs to contain sizeof(structpst_num_item) 1470 // allocate an array of count num_recs to contain sizeof(structpst_num_item)
1471 na_ptr->items = (struct pst_num_item**) xmalloc(sizeof(struct pst_num_item)*num_list); 1471 na_ptr->items = (struct pst_num_item**) xmalloc(sizeof(struct pst_num_item)*num_list);
1472 na_ptr->count_item = num_list; 1472 na_ptr->count_item = num_list;
1473 na_ptr->orig_count = num_list; 1473 na_ptr->orig_count = num_list;
1474 na_ptr->count_array = num_recs; // each record will have a record of the total number of records 1474 na_ptr->count_array = (int32_t)num_recs; // each record will have a record of the total number of records
1475 for (x=0; x<num_list; x++) na_ptr->items[x] = NULL; 1475 for (x=0; x<num_list; x++) na_ptr->items[x] = NULL;
1476 x = 0; 1476 x = 0;
1477 1477
1478 DEBUG_EMAIL(("going to read %i (%#x) items\n", na_ptr->count_item, na_ptr->count_item)); 1478 DEBUG_EMAIL(("going to read %i (%#x) items\n", na_ptr->count_item, na_ptr->count_item));
1479 1479
1480 fr_ptr = list_start; // initialize fr_ptr to the start of the list. 1480 fr_ptr = list_start; // initialize fr_ptr to the start of the list.
1481 for (cur_list=0; cur_list<num_list; cur_list++) { //we will increase fr_ptr as we progress through index 1481 for (cur_list=0; cur_list<num_list; cur_list++) { //we will increase fr_ptr as we progress through index
1482 unsigned char* value_pointer = NULL; // needed for block type 2 with values larger than 4 bytes 1482 unsigned char* value_pointer = NULL; // needed for block type 2 with values larger than 4 bytes
1483 size_t value_size = 0; 1483 size_t value_size = 0;
1484 if (block_type == (int32_t)1) { 1484 if (block_type == 1) {
1485 memcpy(&table_rec, fr_ptr, sizeof(table_rec)); 1485 memcpy(&table_rec, fr_ptr, sizeof(table_rec));
1486 LE16_CPU(table_rec.type); 1486 LE16_CPU(table_rec.type);
1487 LE16_CPU(table_rec.ref_type); 1487 LE16_CPU(table_rec.ref_type);
1488 //LE32_CPU(table_rec.value); // done later, some may be order invariant 1488 //LE32_CPU(table_rec.value); // done later, some may be order invariant
1489 fr_ptr += sizeof(table_rec); 1489 fr_ptr += sizeof(table_rec);
1490 } else if (block_type == (int32_t)2) { 1490 } else if (block_type == 2) {
1491 // we will copy the table2_rec values into a table_rec record so that we can keep the rest of the code 1491 // we will copy the table2_rec values into a table_rec record so that we can keep the rest of the code
1492 memcpy(&table2_rec, fr_ptr, sizeof(table2_rec)); 1492 memcpy(&table2_rec, fr_ptr, sizeof(table2_rec));
1493 LE16_CPU(table2_rec.ref_type); 1493 LE16_CPU(table2_rec.ref_type);
1494 LE16_CPU(table2_rec.type); 1494 LE16_CPU(table2_rec.type);
1495 LE16_CPU(table2_rec.ind2_off); 1495 LE16_CPU(table2_rec.ind2_off);
1718 } 1718 }
1719 1719
1720 1720
1721 int pst_process(pst_num_array *list , pst_item *item, pst_item_attach *attach) { 1721 int pst_process(pst_num_array *list , pst_item *item, pst_item_attach *attach) {
1722 int32_t x, t; 1722 int32_t x, t;
1723 int32_t next = 0; 1723 int next = 0;
1724 pst_item_extra_field *ef; 1724 pst_item_extra_field *ef;
1725 1725
1726 DEBUG_ENT("pst_process"); 1726 DEBUG_ENT("pst_process");
1727 if (!item) { 1727 if (!item) {
1728 DEBUG_EMAIL(("item cannot be NULL.\n")); 1728 DEBUG_EMAIL(("item cannot be NULL.\n"));
1750 break; 1750 break;
1751 case 0x0002: // PR_ALTERNATE_RECIPIENT_ALLOWED 1751 case 0x0002: // PR_ALTERNATE_RECIPIENT_ALLOWED
1752 // If set to true, the sender allows this email to be autoforwarded 1752 // If set to true, the sender allows this email to be autoforwarded
1753 DEBUG_EMAIL(("AutoForward allowed - ")); 1753 DEBUG_EMAIL(("AutoForward allowed - "));
1754 MALLOC_EMAIL(item); 1754 MALLOC_EMAIL(item);
1755 if (*((short int*)list->items[x]->data) != 0) { 1755 if (*(int16_t*)list->items[x]->data != 0) {
1756 DEBUG_EMAIL(("True\n")); 1756 DEBUG_EMAIL(("True\n"));
1757 item->email->autoforward = 1; 1757 item->email->autoforward = 1;
1758 } else { 1758 } else {
1759 DEBUG_EMAIL(("False\n")); 1759 DEBUG_EMAIL(("False\n"));
1760 item->email->autoforward = -1; 1760 item->email->autoforward = -1;
1772 DEBUG_EMAIL(("Importance Level - ")); 1772 DEBUG_EMAIL(("Importance Level - "));
1773 MALLOC_EMAIL(item); 1773 MALLOC_EMAIL(item);
1774 memcpy(&(item->email->importance), list->items[x]->data, sizeof(item->email->importance)); 1774 memcpy(&(item->email->importance), list->items[x]->data, sizeof(item->email->importance));
1775 LE32_CPU(item->email->importance); 1775 LE32_CPU(item->email->importance);
1776 t = item->email->importance; 1776 t = item->email->importance;
1777 DEBUG_EMAIL(("%s [%i]\n", (t==0?"Low":(t==1?"Normal":"High")), t)); 1777 DEBUG_EMAIL(("%s [%i]\n", ((int)t==0?"Low":((int)t==1?"Normal":"High")), t));
1778 break; 1778 break;
1779 case 0x001A: // PR_MESSAGE_CLASS Ascii type of messages - NOT FOLDERS 1779 case 0x001A: // PR_MESSAGE_CLASS Ascii type of messages - NOT FOLDERS
1780 // must be case insensitive 1780 // must be case insensitive
1781 DEBUG_EMAIL(("IPM.x - ")); 1781 DEBUG_EMAIL(("IPM.x - "));
1782 LIST_COPY(item->ascii_type, (char*)); 1782 LIST_COPY(item->ascii_type, (char*));
1826 DEBUG_EMAIL(("%s [%i]\n", (t<0?"NonUrgent":(t==0?"Normal":"Urgent")), t)); 1826 DEBUG_EMAIL(("%s [%i]\n", (t<0?"NonUrgent":(t==0?"Normal":"Urgent")), t));
1827 break; 1827 break;
1828 case 0x0029:// PR_READ_RECEIPT_REQUESTED 1828 case 0x0029:// PR_READ_RECEIPT_REQUESTED
1829 DEBUG_EMAIL(("Read Receipt - ")); 1829 DEBUG_EMAIL(("Read Receipt - "));
1830 MALLOC_EMAIL(item); 1830 MALLOC_EMAIL(item);
1831 if (*(short int*)list->items[x]->data != 0) { 1831 if (*(int16_t*)list->items[x]->data != 0) {
1832 DEBUG_EMAIL(("True\n")); 1832 DEBUG_EMAIL(("True\n"));
1833 item->email->read_receipt = 1; 1833 item->email->read_receipt = 1;
1834 } else { 1834 } else {
1835 DEBUG_EMAIL(("False\n")); 1835 DEBUG_EMAIL(("False\n"));
1836 item->email->read_receipt = 0; 1836 item->email->read_receipt = 0;
1837 } 1837 }
1838 break; 1838 break;
1839 case 0x002B: // PR_RECIPIENT_REASSIGNMENT_PROHIBITED 1839 case 0x002B: // PR_RECIPIENT_REASSIGNMENT_PROHIBITED
1840 DEBUG_EMAIL(("Reassignment Prohibited (Private) - ")); 1840 DEBUG_EMAIL(("Reassignment Prohibited (Private) - "));
1841 if (*(short int*)list->items[x]->data != 0) { 1841 if (*(int16_t*)list->items[x]->data != 0) {
1842 DEBUG_EMAIL(("True\n")); 1842 DEBUG_EMAIL(("True\n"));
1843 item->private_member = 1; 1843 item->private_member = 1;
1844 } else { 1844 } else {
1845 DEBUG_EMAIL(("False\n")); 1845 DEBUG_EMAIL(("False\n"));
1846 item->private_member = 0; 1846 item->private_member = 0;
1855 DEBUG_EMAIL(("Original Sensitivity - ")); 1855 DEBUG_EMAIL(("Original Sensitivity - "));
1856 MALLOC_EMAIL(item); 1856 MALLOC_EMAIL(item);
1857 memcpy(&(item->email->orig_sensitivity), list->items[x]->data, sizeof(item->email->orig_sensitivity)); 1857 memcpy(&(item->email->orig_sensitivity), list->items[x]->data, sizeof(item->email->orig_sensitivity));
1858 LE32_CPU(item->email->orig_sensitivity); 1858 LE32_CPU(item->email->orig_sensitivity);
1859 t = item->email->orig_sensitivity; 1859 t = item->email->orig_sensitivity;
1860 DEBUG_EMAIL(("%s [%i]\n", (t==0?"None":(t==1?"Personal": 1860 DEBUG_EMAIL(("%s [%i]\n", ((int)t==0?"None":((int)t==1?"Personal":
1861 (t==2?"Private":"Company Confidential"))), t)); 1861 ((int)t==2?"Private":"Company Confidential"))), t));
1862 break; 1862 break;
1863 case 0x0036: // PR_SENSITIVITY 1863 case 0x0036: // PR_SENSITIVITY
1864 // sender's opinion of the sensitivity of an email 1864 // sender's opinion of the sensitivity of an email
1865 // 0 - None 1865 // 0 - None
1866 // 1 - Personal 1866 // 1 - Personal
1869 DEBUG_EMAIL(("Sensitivity - ")); 1869 DEBUG_EMAIL(("Sensitivity - "));
1870 MALLOC_EMAIL(item); 1870 MALLOC_EMAIL(item);
1871 memcpy(&(item->email->sensitivity), list->items[x]->data, sizeof(item->email->sensitivity)); 1871 memcpy(&(item->email->sensitivity), list->items[x]->data, sizeof(item->email->sensitivity));
1872 LE32_CPU(item->email->sensitivity); 1872 LE32_CPU(item->email->sensitivity);
1873 t = item->email->sensitivity; 1873 t = item->email->sensitivity;
1874 DEBUG_EMAIL(("%s [%i]\n", (t==0?"None":(t==1?"Personal": 1874 DEBUG_EMAIL(("%s [%i]\n", ((int)t==0?"None":((int)t==1?"Personal":
1875 (t==2?"Private":"Company Confidential"))), t)); 1875 ((int)t==2?"Private":"Company Confidential"))), t));
1876 break; 1876 break;
1877 case 0x0037: // PR_SUBJECT raw subject 1877 case 0x0037: // PR_SUBJECT raw subject
1878 // if (list->items[x]->id == 0x0037) {
1879 DEBUG_EMAIL(("Raw Subject - ")); 1878 DEBUG_EMAIL(("Raw Subject - "));
1880 MALLOC_EMAIL(item); 1879 MALLOC_EMAIL(item);
1881 item->email->subject = (pst_item_email_subject*) realloc(item->email->subject, sizeof(pst_item_email_subject)); 1880 item->email->subject = (pst_item_email_subject*) realloc(item->email->subject, sizeof(pst_item_email_subject));
1882 memset(item->email->subject, 0, sizeof(pst_item_email_subject)); 1881 memset(item->email->subject, 0, sizeof(pst_item_email_subject));
1883 DEBUG_EMAIL((" [size = %i] ", list->items[x]->size)); 1882 DEBUG_EMAIL((" [size = %i] ", list->items[x]->size));
1890 memset(item->email->subject->subj, 0, list->items[x]->size+1); 1889 memset(item->email->subject->subj, 0, list->items[x]->size+1);
1891 memcpy(item->email->subject->subj, list->items[x]->data, list->items[x]->size); 1890 memcpy(item->email->subject->subj, list->items[x]->data, list->items[x]->size);
1892 } else { 1891 } else {
1893 DEBUG_EMAIL(("Raw Subject has control codes\n")); 1892 DEBUG_EMAIL(("Raw Subject has control codes\n"));
1894 // there might be some control bytes in the first and second bytes 1893 // there might be some control bytes in the first and second bytes
1895 item->email->subject->off1 = list->items[x]->data[0]; 1894 item->email->subject->off1 = (int)(unsigned)list->items[x]->data[0];
1896 item->email->subject->off2 = list->items[x]->data[1]; 1895 item->email->subject->off2 = (int)(unsigned)list->items[x]->data[1];
1897 item->email->subject->subj = realloc(item->email->subject->subj, (list->items[x]->size-2)+1); 1896 item->email->subject->subj = realloc(item->email->subject->subj, list->items[x]->size-1);
1898 memset(item->email->subject->subj, 0, list->items[x]->size-1); 1897 memset(item->email->subject->subj, 0, list->items[x]->size-1);
1899 memcpy(item->email->subject->subj, &(list->items[x]->data[2]), list->items[x]->size-2); 1898 memcpy(item->email->subject->subj, &(list->items[x]->data[2]), list->items[x]->size-2);
1900 } 1899 }
1901 DEBUG_EMAIL(("%s\n", item->email->subject->subj)); 1900 DEBUG_EMAIL(("%s\n", item->email->subject->subj));
1902 } else { 1901 } else {
2101 break; 2100 break;
2102 case 0x0E01: // PR_DELETE_AFTER_SUBMIT 2101 case 0x0E01: // PR_DELETE_AFTER_SUBMIT
2103 // I am not too sure how this works 2102 // I am not too sure how this works
2104 DEBUG_EMAIL(("Delete after submit - ")); 2103 DEBUG_EMAIL(("Delete after submit - "));
2105 MALLOC_EMAIL(item); 2104 MALLOC_EMAIL(item);
2106 if (*(int16_t*) list->items[x]->data != 0) { 2105 if (*(int16_t*)list->items[x]->data != 0) {
2107 DEBUG_EMAIL(("True\n")); 2106 DEBUG_EMAIL(("True\n"));
2108 item->email->delete_after_submit = 1; 2107 item->email->delete_after_submit = 1;
2109 } else { 2108 } else {
2110 DEBUG_EMAIL(("False\n")); 2109 DEBUG_EMAIL(("False\n"));
2111 item->email->delete_after_submit = 0; 2110 item->email->delete_after_submit = 0;
2355 DEBUG_EMAIL(("%i\n", item->folder->unseen_email_count)); 2354 DEBUG_EMAIL(("%i\n", item->folder->unseen_email_count));
2356 break; 2355 break;
2357 case 0x360A: // PR_SUBFOLDERS Has children 2356 case 0x360A: // PR_SUBFOLDERS Has children
2358 DEBUG_EMAIL(("Has Subfolders - ")); 2357 DEBUG_EMAIL(("Has Subfolders - "));
2359 MALLOC_FOLDER(item); 2358 MALLOC_FOLDER(item);
2360 if (*((int32_t*)list->items[x]->data) != 0) { 2359 if (*(int32_t*)list->items[x]->data != 0) {
2361 DEBUG_EMAIL(("True\n")); 2360 DEBUG_EMAIL(("True\n"));
2362 item->folder->subfolder = 1; 2361 item->folder->subfolder = 1;
2363 } else { 2362 } else {
2364 DEBUG_EMAIL(("False\n")); 2363 DEBUG_EMAIL(("False\n"));
2365 item->folder->subfolder = 0; 2364 item->folder->subfolder = 0;
2752 DEBUG_EMAIL(("%s\n", item->contact->assistant_name)); 2751 DEBUG_EMAIL(("%s\n", item->contact->assistant_name));
2753 break; 2752 break;
2754 case 0x3A40: // PR_SEND_RICH_INFO 2753 case 0x3A40: // PR_SEND_RICH_INFO
2755 DEBUG_EMAIL(("Can receive Rich Text - ")); 2754 DEBUG_EMAIL(("Can receive Rich Text - "));
2756 MALLOC_CONTACT(item); 2755 MALLOC_CONTACT(item);
2757 if(*(int16_t*)list->items[x]->data != 0) { 2756 if (*(int16_t*)list->items[x]->data != 0) {
2758 DEBUG_EMAIL(("True\n")); 2757 DEBUG_EMAIL(("True\n"));
2759 item->contact->rich_text = 1; 2758 item->contact->rich_text = 1;
2760 } else { 2759 } else {
2761 DEBUG_EMAIL(("False\n")); 2760 DEBUG_EMAIL(("False\n"));
2762 item->contact->rich_text = 0; 2761 item->contact->rich_text = 0;
3276 - 0x1003 - Array of 32bit values 3275 - 0x1003 - Array of 32bit values
3277 - 0x101E - Array of Strings 3276 - 0x101E - Array of Strings
3278 - 0x1102 - Array of Binary data 3277 - 0x1102 - Array of Binary data
3279 */ 3278 */
3280 // DEBUG_EMAIL(("Unknown id [%#x, size=%#x]\n", list->items[x]->id, list->items[x]->size)); 3279 // DEBUG_EMAIL(("Unknown id [%#x, size=%#x]\n", list->items[x]->id, list->items[x]->size));
3281 if (list->items[x]->type == 0x02) { 3280 if (list->items[x]->type == (uint32_t)0x02) {
3282 DEBUG_EMAIL(("Unknown 16bit int = %hi\n", *(int16_t*)list->items[x]->data)); 3281 DEBUG_EMAIL(("Unknown 16bit int = %hi\n", *(int16_t*)list->items[x]->data));
3283 } else if (list->items[x]->type == 0x03) { 3282 } else if (list->items[x]->type == (uint32_t)0x03) {
3284 DEBUG_EMAIL(("Unknown 32bit int = %i\n", *(int32_t*)list->items[x]->data)); 3283 DEBUG_EMAIL(("Unknown 32bit int = %i\n", *(int32_t*)list->items[x]->data));
3285 } else if (list->items[x]->type == 0x0b) { 3284 } else if (list->items[x]->type == (uint32_t)0x0b) {
3286 DEBUG_EMAIL(("Unknown 16bit boolean = %s [%hi]\n", 3285 DEBUG_EMAIL(("Unknown 16bit boolean = %s [%hi]\n",
3287 (*((int16_t*)list->items[x]->data)!=0?"True":"False"), 3286 (*((int16_t*)list->items[x]->data)!=0?"True":"False"),
3288 *((int16_t*)list->items[x]->data))); 3287 *((int16_t*)list->items[x]->data)));
3289 } else if (list->items[x]->type == 0x1e) { 3288 } else if (list->items[x]->type == (uint32_t)0x1e) {
3290 DEBUG_EMAIL(("Unknown String Data = \"%s\" [%#x]\n", 3289 DEBUG_EMAIL(("Unknown String Data = \"%s\" [%#x]\n",
3291 list->items[x]->data, list->items[x]->type)); 3290 list->items[x]->data, list->items[x]->type));
3292 } else if (list->items[x]->type == 0x40) { 3291 } else if (list->items[x]->type == (uint32_t)0x40) {
3293 DEBUG_EMAIL(("Unknown Date = \"%s\" [%#x]\n", 3292 DEBUG_EMAIL(("Unknown Date = \"%s\" [%#x]\n",
3294 fileTimeToAscii((FILETIME*)list->items[x]->data), 3293 fileTimeToAscii((FILETIME*)list->items[x]->data),
3295 list->items[x]->type)); 3294 list->items[x]->type));
3296 } else if (list->items[x]->type == 0x102) { 3295 } else if (list->items[x]->type == (uint32_t)0x102) {
3297 DEBUG_EMAIL(("Unknown Binary Data [size = %#x]\n", 3296 DEBUG_EMAIL(("Unknown Binary Data [size = %#x]\n",
3298 list->items[x]->size)); 3297 list->items[x]->size));
3299 DEBUG_HEXDUMP(list->items[x]->data, list->items[x]->size); 3298 DEBUG_HEXDUMP(list->items[x]->data, list->items[x]->size);
3300 } else if (list->items[x]->type == 0x101E) { 3299 } else if (list->items[x]->type == (uint32_t)0x101E) {
3301 DEBUG_EMAIL(("Unknown Array of Strings [%#x]\n", 3300 DEBUG_EMAIL(("Unknown Array of Strings [%#x]\n",
3302 list->items[x]->type)); 3301 list->items[x]->type));
3303 } else { 3302 } else {
3304 DEBUG_EMAIL(("Unknown Not Printable [%#x]\n", 3303 DEBUG_EMAIL(("Unknown Not Printable [%#x]\n",
3305 list->items[x]->type)); 3304 list->items[x]->type));
3430 memcpy(&block_head, buf, sizeof(block_head)); 3429 memcpy(&block_head, buf, sizeof(block_head));
3431 LE16_CPU(block_head.type); 3430 LE16_CPU(block_head.type);
3432 LE16_CPU(block_head.count); 3431 LE16_CPU(block_head.count);
3433 3432
3434 if (block_head.type != (uint16_t)0x0002) { // some sort of constant? 3433 if (block_head.type != (uint16_t)0x0002) { // some sort of constant?
3435 WARN(("Unknown constant [%#x] at start of id2 values [offset %#llx].\n", block_head.type, list->offset)); 3434 WARN(("Unknown constant [%#hx] at start of id2 values [offset %#llx].\n", block_head.type, list->offset));
3436 if (buf) free(buf); 3435 if (buf) free(buf);
3437 DEBUG_RET(); 3436 DEBUG_RET();
3438 return NULL; 3437 return NULL;
3439 } 3438 }
3440 3439
3928 if ((ptr = pst_getID(pf, x)) == NULL) { 3927 if ((ptr = pst_getID(pf, x)) == NULL) {
3929 WARN(("Error. Cannot find ID [%#x] during multi-block read\n", x)); 3928 WARN(("Error. Cannot find ID [%#x] during multi-block read\n", x));
3930 buf3 = (char*) realloc(buf3, size+1); 3929 buf3 = (char*) realloc(buf3, size+1);
3931 buf3[size] = '\0'; 3930 buf3[size] = '\0';
3932 *buf = buf3; 3931 *buf = buf3;
3933 fseek(pf->fp, fpos, SEEK_SET); 3932 (void)fseek(pf->fp, fpos, SEEK_SET);
3934 DEBUG_RET(); 3933 DEBUG_RET();
3935 return size; 3934 return size;
3936 } 3935 }
3937 if ((z = pst_read_block_size(pf, ptr->offset, ptr->size, &buf2, do_enc, fdepth-1)) < ptr->size) { 3936 if ((z = pst_read_block_size(pf, ptr->offset, ptr->size, &buf2, do_enc, fdepth-1)) < ptr->size) {
3938 buf3 = (char*) realloc(buf3, size+1); 3937 buf3 = (char*) realloc(buf3, size+1);
3939 buf3[size] = '\0'; 3938 buf3[size] = '\0';
3940 *buf = buf3; 3939 *buf = buf3;
3941 fseek(pf->fp, fpos, SEEK_SET); 3940 (void)fseek(pf->fp, fpos, SEEK_SET);
3942 DEBUG_RET(); 3941 DEBUG_RET();
3943 return size; 3942 return size;
3944 } 3943 }
3945 DEBUG_READ(("Melding newley retrieved block with bigger one. New size is %i\n", size+z)); 3944 DEBUG_READ(("Melding newley retrieved block with bigger one. New size is %i\n", size+z));
3946 buf3 = (char*) realloc(buf3, size+z+1); //plus one so that we can null terminate it later 3945 buf3 = (char*) realloc(buf3, size+z+1); //plus one so that we can null terminate it later
4033 DEBUG_ENT("pst_getAtPos"); 4032 DEBUG_ENT("pst_getAtPos");
4034 if (fseek(fp, pos, SEEK_SET) == -1) { 4033 if (fseek(fp, pos, SEEK_SET) == -1) {
4035 DEBUG_RET(); 4034 DEBUG_RET();
4036 return 1; 4035 return 1;
4037 } 4036 }
4038 if (fread(buf, 1, size, fp) < size) { 4037 if (fread(buf, (size_t)1, size, fp) < size) {
4039 DEBUG_RET(); 4038 DEBUG_RET();
4040 return 2; 4039 return 2;
4041 } 4040 }
4042 DEBUG_RET(); 4041 DEBUG_RET();
4043 return 0; 4042 return 0;
4044 } 4043 }
4045 4044
4046 4045
4047 int pst_get (FILE *fp, void *buf, size_t size) { 4046 int pst_get (FILE *fp, void *buf, size_t size) {
4048 DEBUG_ENT("pst_get"); 4047 DEBUG_ENT("pst_get");
4049 if (fread(buf, 1, size, fp) < size) { 4048 if (fread(buf, (size_t)1, size, fp) < size) {
4050 DEBUG_RET(); 4049 DEBUG_RET();
4051 return 1; 4050 return 1;
4052 } 4051 }
4053 DEBUG_RET(); 4052 DEBUG_RET();
4054 return 0; 4053 return 0;
4085 free(*b); 4084 free(*b);
4086 } 4085 }
4087 4086
4088 DEBUG_INDEX(("id = %#x, record size = %#x, offset = %#x\n", id, rec->size, rec->offset)); 4087 DEBUG_INDEX(("id = %#x, record size = %#x, offset = %#x\n", id, rec->size, rec->offset));
4089 *b = (char*) xmalloc(rec->size+1); 4088 *b = (char*) xmalloc(rec->size+1);
4090 rsize = fread(*b, 1, rec->size, pf->fp); 4089 rsize = fread(*b, (size_t)1, rec->size, pf->fp);
4091 if (rsize != rec->size) { 4090 if (rsize != rec->size) {
4092 DEBUG_WARN(("Didn't read all the size. fread returned less [%i instead of %i]\n", rsize, rec->size)); 4091 DEBUG_WARN(("Didn't read all the size. fread returned less [%i instead of %i]\n", rsize, rec->size));
4093 if (feof(pf->fp)) { 4092 if (feof(pf->fp)) {
4094 DEBUG_WARN(("We tried to read past the end of the file [offset %#x, size %#x]\n", rec->offset, rec->size)); 4093 DEBUG_WARN(("We tried to read past the end of the file [offset %#x, size %#x]\n", rec->offset, rec->size));
4095 } else if (ferror(pf->fp)) { 4094 } else if (ferror(pf->fp)) {
4130 if (h->buf) { 4129 if (h->buf) {
4131 *(h->buf) = b; 4130 *(h->buf) = b;
4132 } else if ((h->base64 == 1) && h->fp) { 4131 } else if ((h->base64 == 1) && h->fp) {
4133 t = base64_encode(b, ret); 4132 t = base64_encode(b, ret);
4134 if (t) { 4133 if (t) {
4135 (void)pst_fwrite(t, 1, strlen(t), h->fp); 4134 (void)pst_fwrite(t, (size_t)1, strlen(t), h->fp);
4136 free(t); // caught by valgrind 4135 free(t); // caught by valgrind
4137 } 4136 }
4138 free(b); 4137 free(b);
4139 } else if (h->fp) { 4138 } else if (h->fp) {
4140 (void)pst_fwrite(b, 1, ret, h->fp); 4139 (void)pst_fwrite(b, (size_t)1, ret, h->fp);
4141 free(b); 4140 free(b);
4142 } else { 4141 } else {
4143 // h-> does not specify any output 4142 // h-> does not specify any output
4144 } 4143 }
4145 4144
4176 if (h->buf) 4175 if (h->buf)
4177 *(h->buf) = buf3; 4176 *(h->buf) = buf3;
4178 else if (h->base64 == 1 && h->fp) { 4177 else if (h->base64 == 1 && h->fp) {
4179 t = base64_encode(buf3, a); 4178 t = base64_encode(buf3, a);
4180 if (t) { 4179 if (t) {
4181 (void)pst_fwrite(t, 1, strlen(t), h->fp); 4180 (void)pst_fwrite(t, (size_t)1, strlen(t), h->fp);
4182 free(t); // caught by valgrind 4181 free(t); // caught by valgrind
4183 } 4182 }
4184 free(buf3); 4183 free(buf3);
4185 } else if (h->fp) { 4184 } else if (h->fp) {
4186 (void)pst_fwrite(buf3, 1, a, h->fp); 4185 (void)pst_fwrite(buf3, (size_t)1, a, h->fp);
4187 free(buf3); 4186 free(buf3);
4188 } else { 4187 } else {
4189 // h-> does not specify any output 4188 // h-> does not specify any output
4190 } 4189 }
4191 DEBUG_RET(); 4190 DEBUG_RET();
4225 memcpy(h->base64_extra_chars, &(buf2[z-b]), b); 4224 memcpy(h->base64_extra_chars, &(buf2[z-b]), b);
4226 h->base64_extra = b; 4225 h->base64_extra = b;
4227 t = base64_encode(buf2, z-b); 4226 t = base64_encode(buf2, z-b);
4228 if (t) { 4227 if (t) {
4229 DEBUG_READ(("writing %i bytes to file as base64 [%i]. Currently %i\n", z, strlen(t), size)); 4228 DEBUG_READ(("writing %i bytes to file as base64 [%i]. Currently %i\n", z, strlen(t), size));
4230 (void)pst_fwrite(t, 1, strlen(t), h->fp); 4229 (void)pst_fwrite(t, (size_t)1, strlen(t), h->fp);
4231 free(t); // caught by valgrind 4230 free(t); // caught by valgrind
4232 } 4231 }
4233 } else if (h->fp) { 4232 } else if (h->fp) {
4234 DEBUG_READ(("writing %i bytes to file. Currently %i\n", z, size)); 4233 DEBUG_READ(("writing %i bytes to file. Currently %i\n", z, size));
4235 (void)pst_fwrite(buf2, 1, z, h->fp); 4234 (void)pst_fwrite(buf2, (size_t)1, z, h->fp);
4236 } else { 4235 } else {
4237 // h-> does not specify any output 4236 // h-> does not specify any output
4238 } 4237 }
4239 size += z; 4238 size += z;
4240 y++; 4239 y++;
4339 DEBUG_RET(); 4338 DEBUG_RET();
4340 return r; 4339 return r;
4341 } 4340 }
4342 4341
4343 4342
4344 char * pst_wide_to_single(char *wt, int32_t size) { 4343 char * pst_wide_to_single(char *wt, size_t size) {
4345 // returns the first byte of each wide char. the size is the number of bytes in source 4344 // returns the first byte of each wide char. the size is the number of bytes in source
4346 char *x, *y; 4345 char *x, *y;
4347 DEBUG_ENT("pst_wide_to_single"); 4346 DEBUG_ENT("pst_wide_to_single");
4348 x = xmalloc((size/2)+1); 4347 x = xmalloc((size/2)+1);
4349 y = x; 4348 y = x;
4360 4359
4361 4360
4362 char *pst_rfc2426_escape(char *str) { 4361 char *pst_rfc2426_escape(char *str) {
4363 static char* buf = NULL; 4362 static char* buf = NULL;
4364 char *ret, *a, *b; 4363 char *ret, *a, *b;
4365 int x = 0, y, z; 4364 size_t x = 0;
4365 int y, z;
4366 DEBUG_ENT("rfc2426_escape"); 4366 DEBUG_ENT("rfc2426_escape");
4367 if (!str) 4367 if (!str)
4368 ret = str; 4368 ret = str;
4369 else { 4369 else {
4370 4370
4421 return r; 4421 return r;
4422 } 4422 }
4423 4423
4424 4424
4425 char *pst_rfc2425_datetime_format(FILETIME *ft) { 4425 char *pst_rfc2425_datetime_format(FILETIME *ft) {
4426 static char* buffer = NULL; 4426 static char buffer[30];
4427 struct tm *stm = NULL; 4427 struct tm *stm = NULL;
4428 DEBUG_ENT("rfc2425_datetime_format"); 4428 DEBUG_ENT("rfc2425_datetime_format");
4429 if (!buffer) buffer = malloc(30); // should be enough for the date as defined below
4430 stm = fileTimeToStructTM(ft); 4429 stm = fileTimeToStructTM(ft);
4431 if (strftime(buffer, 30, "%Y-%m-%dT%H:%M:%SZ", stm)==0) { 4430 if (strftime(buffer, sizeof(buffer), "%Y-%m-%dT%H:%M:%SZ", stm)==0) {
4432 DEBUG_INFO(("Problem occured formatting date\n")); 4431 DEBUG_INFO(("Problem occured formatting date\n"));
4433 } 4432 }
4434 DEBUG_RET(); 4433 DEBUG_RET();
4435 return buffer; 4434 return buffer;
4436 } 4435 }
4437 4436
4438 4437
4439 char *pst_rfc2445_datetime_format(FILETIME *ft) { 4438 char *pst_rfc2445_datetime_format(FILETIME *ft) {
4440 static char* buffer = NULL; 4439 static char buffer[30];
4441 struct tm *stm = NULL; 4440 struct tm *stm = NULL;
4442 DEBUG_ENT("rfc2445_datetime_format"); 4441 DEBUG_ENT("rfc2445_datetime_format");
4443 if (!buffer) buffer = malloc(30); // should be enough for the date as defined below
4444 stm = fileTimeToStructTM(ft); 4442 stm = fileTimeToStructTM(ft);
4445 if (strftime(buffer, 30, "%Y%m%dT%H%M%SZ", stm)==0) { 4443 if (strftime(buffer, sizeof(buffer), "%Y%m%dT%H%M%SZ", stm)==0) {
4446 DEBUG_INFO(("Problem occured formatting date\n")); 4444 DEBUG_INFO(("Problem occured formatting date\n"));
4447 } 4445 }
4448 DEBUG_RET(); 4446 DEBUG_RET();
4449 return buffer; 4447 return buffer;
4450 } 4448 }