- Timestamp:
- 05/01/08 00:06:22 (17 years ago)
- Location:
- trunk/lib
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/lru_cache.c
r108 r111 101 101 lru_cache* ret_val; 102 102 103 if(max_keys < 2)104 return NULL;105 106 103 ret_val = (lru_cache*)malloc(sizeof(lru_cache)); 107 104 if(ret_val == NULL) 108 105 return NULL; 109 106 110 ret_val->num_buckets = max_keys/lru_cache_floor_log2(max_keys); 111 if(ret_val->num_buckets < 1) 112 ret_val->num_buckets = 1; 113 107 if(max_keys == 0) 108 ret_val->num_buckets = 2048; 109 else 110 { 111 ret_val->num_buckets = max_keys/lru_cache_floor_log2(max_keys); 112 if(ret_val->num_buckets < 1) 113 ret_val->num_buckets = 1; 114 } 115 114 116 ret_val->table 115 117 = (lru_cache_element**)malloc(sizeof(lru_cache_element*) … … 193 195 { /* We didn't find an identical index. */ 194 196 195 if( ht->num_keys >= ht->max_keys)197 if((ht->max_keys != 0) && (ht->num_keys >= ht->max_keys)) 196 198 { /* Eliminate the least recently used item, but reuse the element 197 199 * structure to minimize reallocation. -
trunk/lib/range_list.c
r106 r111 28 28 #define RANGE_LIST_ALLOC_SIZE 256 29 29 30 30 #if 0 31 31 static void range_list_print(const range_list* rl) 32 32 { … … 38 38 fprintf(stderr, "\n"); 39 39 } 40 40 #endif 41 41 42 42 /* -
trunk/lib/regfi.c
r110 r111 11 11 * This program is free software; you can redistribute it and/or modify 12 12 * it under the terms of the GNU General Public License as published by 13 * the Free Software Foundation; version 2of the License.13 * the Free Software Foundation; version 3 of the License. 14 14 * 15 15 * This program is distributed in the hope that it will be useful, … … 372 372 * 373 373 *****************************************************************************/ 374 staticbool regfi_parse_cell(int fd, uint32 offset, uint8* hdr, uint32 hdr_len,375 374 bool regfi_parse_cell(int fd, uint32 offset, uint8* hdr, uint32 hdr_len, 375 uint32* cell_length, bool* unalloc) 376 376 { 377 377 uint32 length; … … 434 434 * block for it. NULL if one doesn't exist. 435 435 *******************************************************************/ 436 staticREGF_HBIN* regfi_lookup_hbin(REGF_FILE* file, uint32 offset)436 REGF_HBIN* regfi_lookup_hbin(REGF_FILE* file, uint32 offset) 437 437 { 438 438 return (REGF_HBIN*)range_list_find_data(file->hbins, offset+REGF_BLOCKSIZE); … … 565 565 566 566 ret_val->offset = offset; 567 /* TODO: is there a way to be more conservative (shorter) with 568 * cell length when cell is unallocated? 569 */ 567 570 ret_val->cell_size = cell_length; 568 571 … … 576 579 } 577 580 578 579 581 ret_val->magic[0] = sk_header[0]; 580 582 ret_val->magic[1] = sk_header[1]; 581 583 584 /* TODO: can additional validation be added here? */ 582 585 ret_val->unknown_tag = SVAL(sk_header, 0x2); 583 586 ret_val->prev_sk_off = IVAL(sk_header, 0x4); … … 621 624 622 625 623 624 /****************************************************************************** 625 TODO: not currently validating against max_size. 626 uint32* regfi_parse_valuelist(REGF_FILE* file, uint32 offset, 627 uint32 num_values, bool strict) 628 { 629 uint32* ret_val; 630 uint32 i, cell_length, length, read_len; 631 bool unalloc; 632 633 if(!regfi_parse_cell(file->fd, offset, NULL, 0, &cell_length, &unalloc)) 634 return NULL; 635 636 if(cell_length != (cell_length & 0xFFFFFFF8)) 637 { 638 if(strict) 639 return NULL; 640 cell_length = cell_length & 0xFFFFFFF8; 641 } 642 if((num_values * sizeof(uint32)) > cell_length-sizeof(uint32)) 643 return NULL; 644 645 read_len = num_values*sizeof(uint32); 646 ret_val = (uint32*)malloc(read_len); 647 if(ret_val == NULL) 648 return NULL; 649 650 length = read_len; 651 if((regfi_read(file->fd, (uint8*)ret_val, &length) != 0) || length != read_len) 652 { 653 free(ret_val); 654 return NULL; 655 } 656 657 for(i=0; i < num_values; i++) 658 { 659 /* Fix endianness */ 660 ret_val[i] = IVAL(&ret_val[i], 0); 661 662 /* Validate the first num_values values to ensure they make sense */ 663 if(strict) 664 { 665 if((ret_val[i] + REGF_BLOCKSIZE > file->file_length) 666 || ((ret_val[i] & 0xFFFFFFF8) != ret_val[i])) 667 { 668 free(ret_val); 669 return NULL; 670 } 671 } 672 } 673 674 return ret_val; 675 } 676 677 678 679 /****************************************************************************** 680 * If !strict, the list may contain NULLs and VK records may point to NULL data. 626 681 ******************************************************************************/ 627 682 REGF_VK_REC** regfi_load_valuelist(REGF_FILE* file, uint32 offset, … … 630 685 { 631 686 REGF_VK_REC** ret_val; 632 REGF_HBIN* sub_hbin; 633 uint8* buf; 634 uint32 i, cell_length, vk_raw_offset, vk_offset, vk_max_length, buf_len; 635 bool unalloc; 636 637 buf_len = sizeof(uint8) * 4 * num_values; 638 buf = (uint8*)zalloc(buf_len); 639 if(buf == NULL) 640 return NULL; 641 642 if(!regfi_parse_cell(file->fd, offset, buf, buf_len, &cell_length, &unalloc)) 643 { 644 free(buf); 645 return NULL; 646 } 687 REGF_HBIN* hbin; 688 uint32 i, vk_offset, vk_max_length; 689 uint32* voffsets; 690 691 if((num_values+1) * sizeof(uint32) > max_size) 692 return NULL; 693 694 /* TODO: For now, everything strict seems to make sense on this call. 695 * Maybe remove the parameter or use it for other things. 696 */ 697 voffsets = regfi_parse_valuelist(file, offset, num_values, true); 698 if(voffsets == NULL) 699 return NULL; 647 700 648 701 ret_val = (REGF_VK_REC**)zalloc(sizeof(REGF_VK_REC*) * num_values); 649 702 if(ret_val == NULL) 650 703 { 651 free(buf); 652 return NULL; 653 } 654 655 for (i=0; i < num_values; i++) 656 { 657 vk_raw_offset = IVAL(buf, i*4); 658 659 sub_hbin = regfi_lookup_hbin(file, vk_raw_offset); 660 if (!sub_hbin) 661 { 662 free(buf); 704 free(voffsets); 705 return NULL; 706 } 707 708 for(i=0; i < num_values; i++) 709 { 710 hbin = regfi_lookup_hbin(file, voffsets[i]); 711 if(!hbin) 712 { 713 free(voffsets); 663 714 free(ret_val); 664 715 return NULL; 665 716 } 666 717 667 vk_offset = v k_raw_offset+ REGF_BLOCKSIZE;668 vk_max_length = sub_hbin->block_size - vk_offset + sizeof(uint32);669 ret_val[i] = regfi_parse_vk(file, vk_offset, vk_max_length, true);718 vk_offset = voffsets[i] + REGF_BLOCKSIZE; 719 vk_max_length = hbin->block_size - vk_offset + sizeof(uint32); 720 ret_val[i] = regfi_parse_vk(file, vk_offset, vk_max_length, strict); 670 721 if(ret_val[i] == NULL) 671 { 672 free(buf); 673 free(ret_val); 674 return NULL; 675 } 676 } 677 678 free(buf); 722 { /* If we're being strict, throw out the whole list. 723 * Otherwise, let it be NULL. 724 */ 725 if(strict) 726 { 727 free(voffsets); 728 free(ret_val); 729 return NULL; 730 } 731 } 732 } 733 734 free(voffsets); 679 735 return ret_val; 680 736 } … … 1460 1516 { 1461 1517 /* TODO: deal with subkey-lists that reference other subkey-lists. */ 1462 printf("DEBUG: magic check failed! \"%c%c\"\n", nk_header[0x0], nk_header[0x1]);1463 1518 return NULL; 1464 1519 } … … 1574 1629 &cell_length, &unalloc)) 1575 1630 return NULL; 1576 1631 1577 1632 ret_val = (REGF_VK_REC*)zalloc(sizeof(REGF_VK_REC)); 1578 1633 if(ret_val == NULL) … … 1585 1640 ret_val->cell_size = max_size & 0xFFFFFFF8; 1586 1641 if((ret_val->cell_size < REGFI_VK_MIN_LENGTH) 1587 || (strict && ret_val->cell_size != (ret_val->cell_size & 0xFFFFFFF8)))1642 || ret_val->cell_size != (ret_val->cell_size & 0xFFFFFFF8)) 1588 1643 { 1589 1644 free(ret_val); … … 1602 1657 raw_data_size = IVAL(vk_header, 0x4); 1603 1658 ret_val->data_size = raw_data_size & ~VK_DATA_IN_OFFSET; 1659 ret_val->data_in_offset = (bool)(raw_data_size & VK_DATA_IN_OFFSET); 1604 1660 ret_val->data_off = IVAL(vk_header, 0x8); 1605 1661 ret_val->type = IVAL(vk_header, 0xC); … … 1697 1753 &cell_length, &unalloc)) 1698 1754 return NULL; 1699 1700 if( cell_length < 8 || ((cell_length & 0xFFFFFFF8) != cell_length))1755 1756 if((cell_length & 0xFFFFFFF8) != cell_length) 1701 1757 return NULL; 1702 1758 1703 1759 if(cell_length - 4 < length) 1704 1760 { 1761 /* TODO: This strict condition has been triggered in multiple registries. 1762 * Not sure the cause, but the data length values are very large, 1763 * such as 53392. 1764 */ 1705 1765 if(strict) 1706 1766 return NULL; -
trunk/lib/smb_deps.c
r84 r111 10 10 * This program is free software; you can redistribute it and/or modify 11 11 * it under the terms of the GNU General Public License as published by 12 * the Free Software Foundation; version 2of the License.12 * the Free Software Foundation; version 3 of the License. 13 13 * 14 14 * This program is distributed in the hope that it will be useful, -
trunk/lib/void_stack.c
r89 r111 8 8 * This program is free software; you can redistribute it and/or modify 9 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; version 2of the License.10 * the Free Software Foundation; version 3 of the License. 11 11 * 12 12 * This program is distributed in the hope that it will be useful,
Note: See TracChangeset
for help on using the changeset viewer.