- Timestamp:
- 01/11/09 15:14:20 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/regfi.c
r129 r131 796 796 797 797 vk_offset = voffsets[i] + REGF_BLOCKSIZE; 798 vk_max_length = hbin->block_size - vk_offset + sizeof(uint32);798 vk_max_length = hbin->block_size + hbin->file_off - vk_offset; 799 799 ret_val[i] = regfi_parse_vk(file, vk_offset, vk_max_length, strict); 800 800 if(ret_val[i] == NULL) … … 1604 1604 { 1605 1605 uint8 nk_header[REGFI_NK_MIN_LENGTH]; 1606 REGF_HBIN *hbin; 1606 1607 REGF_NK_REC* ret_val; 1607 uint32 length ;1608 uint32 c ell_length;1608 uint32 length,cell_length; 1609 uint32 class_offset, class_maxsize; 1609 1610 bool unalloc = false; 1610 1611 … … 1722 1723 if(ret_val->classname_off != REGF_OFFSET_NONE) 1723 1724 { 1724 ret_val->classname 1725 = regfi_parse_classname(file, ret_val->classname_off+REGF_BLOCKSIZE, 1726 &ret_val->classname_length, strict); 1725 hbin = regfi_lookup_hbin(file, ret_val->classname_off); 1726 if(hbin) 1727 { 1728 class_offset = ret_val->classname_off+REGF_BLOCKSIZE; 1729 class_maxsize = hbin->block_size + hbin->file_off - class_offset; 1730 ret_val->classname 1731 = regfi_parse_classname(file, class_offset, &ret_val->classname_length, 1732 class_maxsize, strict); 1733 } 1734 else 1735 ret_val->classname = NULL; 1727 1736 /* 1728 1737 if(strict && ret_val->classname == NULL) … … 1735 1744 1736 1745 1737 /*******************************************************************/1738 /* XXX: Not currently validating against hbin length. */1739 /*******************************************************************/1740 1746 char* regfi_parse_classname(REGF_FILE* file, uint32 offset, 1741 uint16* name_length, bool strict)1747 uint16* name_length, uint32 max_size, bool strict) 1742 1748 { 1743 1749 char* ret_val = NULL; … … 1748 1754 if(*name_length > 0 && offset != REGF_OFFSET_NONE 1749 1755 && offset == (offset & 0xFFFFFFF8)) 1750 { 1756 { 1751 1757 if(!regfi_parse_cell(file->fd, offset, NULL, 0, &cell_length, &unalloc)) 1752 1758 return NULL; 1753 1759 1754 if(cell_length < *name_length) 1760 if((cell_length & 0xFFFFFFF8) != cell_length) 1761 return NULL; 1762 1763 if(cell_length > max_size) 1755 1764 { 1756 1765 if(strict) 1757 1766 return NULL; 1758 *name_length = cell_length & 0xFFFFFFF8; 1767 cell_length = max_size; 1768 } 1769 1770 if((cell_length - 4) < *name_length) 1771 { 1772 if(strict) 1773 return NULL; 1774 *name_length = cell_length - 4; 1759 1775 } 1760 1776 … … 1784 1800 { 1785 1801 REGF_VK_REC* ret_val; 1802 REGF_HBIN *hbin; 1786 1803 uint8 vk_header[REGFI_VK_MIN_LENGTH]; 1787 1804 uint32 raw_data_size, length, cell_length; 1805 uint32 data_offset, data_maxsize; 1788 1806 bool unalloc = false; 1789 1807 … … 1878 1896 else 1879 1897 { 1880 ret_val->data = regfi_parse_data(file, ret_val->data_off+REGF_BLOCKSIZE, 1881 raw_data_size, strict); 1898 hbin = regfi_lookup_hbin(file, ret_val->data_off); 1899 if(hbin) 1900 { 1901 data_offset = ret_val->data_off+REGF_BLOCKSIZE; 1902 data_maxsize = hbin->block_size + hbin->file_off - data_offset; 1903 ret_val->data = regfi_parse_data(file, data_offset, raw_data_size, 1904 data_maxsize, strict); 1905 } 1906 else 1907 ret_val->data = NULL; 1908 1882 1909 if(strict && (ret_val->data == NULL)) 1883 1910 { … … 1892 1919 1893 1920 1894 uint8* regfi_parse_data(REGF_FILE* file, uint32 offset, uint32 length, bool strict) 1921 uint8* regfi_parse_data(REGF_FILE* file, uint32 offset, uint32 length, 1922 uint32 max_size, bool strict) 1895 1923 { 1896 1924 uint8* ret_val; … … 1921 1949 if((cell_length & 0xFFFFFFF8) != cell_length) 1922 1950 return NULL; 1951 1952 if(cell_length > max_size) 1953 { 1954 if(strict) 1955 return NULL; 1956 else 1957 cell_length = max_size; 1958 } 1923 1959 1924 1960 if(cell_length - 4 < length) … … 1933 1969 length = cell_length - 4; 1934 1970 } 1935 1936 /* XXX: There is currently no check to ensure the data1937 * cell doesn't cross HBIN boundary.1938 */1939 1971 1940 1972 if((ret_val = (uint8*)zalloc(sizeof(uint8)*length)) == NULL)
Note: See TracChangeset
for help on using the changeset viewer.