diff options
Diffstat (limited to 'src/burn/engine')
-rw-r--r-- | src/burn/engine/section.cpp | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/burn/engine/section.cpp b/src/burn/engine/section.cpp index 1fd6cce4..a9c7927e 100644 --- a/src/burn/engine/section.cpp +++ b/src/burn/engine/section.cpp | |||
@@ -26,7 +26,7 @@ typedef struct _BURN_SECTION_HEADER | |||
26 | 26 | ||
27 | DWORD dwFormat; | 27 | DWORD dwFormat; |
28 | DWORD cContainers; | 28 | DWORD cContainers; |
29 | DWORD rgcbContainers[116]; | 29 | DWORD rgcbContainers[1]; |
30 | } BURN_SECTION_HEADER; | 30 | } BURN_SECTION_HEADER; |
31 | 31 | ||
32 | static HRESULT VerifySectionMatchesMemoryPEHeader( | 32 | static HRESULT VerifySectionMatchesMemoryPEHeader( |
@@ -53,6 +53,7 @@ extern "C" HRESULT SectionInitialize( | |||
53 | IMAGE_SECTION_HEADER sectionHeader = { }; | 53 | IMAGE_SECTION_HEADER sectionHeader = { }; |
54 | DWORD_PTR dwOriginalChecksumAndSignatureOffset = 0; | 54 | DWORD_PTR dwOriginalChecksumAndSignatureOffset = 0; |
55 | BURN_SECTION_HEADER* pBurnSectionHeader = NULL; | 55 | BURN_SECTION_HEADER* pBurnSectionHeader = NULL; |
56 | DWORD cMaxContainers = 0; | ||
56 | 57 | ||
57 | pSection->hEngineFile = hEngineFile; | 58 | pSection->hEngineFile = hEngineFile; |
58 | ExitOnInvalidHandleWithLastError(pSection->hEngineFile, hr, "Failed to open handle to engine process path."); | 59 | ExitOnInvalidHandleWithLastError(pSection->hEngineFile, hr, "Failed to open handle to engine process path."); |
@@ -142,8 +143,7 @@ extern "C" HRESULT SectionInitialize( | |||
142 | } | 143 | } |
143 | if (sizeof(IMAGE_SECTION_HEADER) > cbRead) | 144 | if (sizeof(IMAGE_SECTION_HEADER) > cbRead) |
144 | { | 145 | { |
145 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); | 146 | ExitWithRootFailure(hr, E_INVALIDDATA, "Failed to read complete image section header, index: %u", i); |
146 | ExitOnRootFailure(hr, "Failed to read complete image section header, index: %u", i); | ||
147 | } | 147 | } |
148 | 148 | ||
149 | // compare header name | 149 | // compare header name |
@@ -156,8 +156,7 @@ extern "C" HRESULT SectionInitialize( | |||
156 | // fail if we hit the end | 156 | // fail if we hit the end |
157 | if (i + 1 >= ntHeader.FileHeader.NumberOfSections) | 157 | if (i + 1 >= ntHeader.FileHeader.NumberOfSections) |
158 | { | 158 | { |
159 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); | 159 | ExitWithRootFailure(hr, E_INVALIDDATA, "Failed to find Burn section."); |
160 | ExitOnRootFailure(hr, "Failed to find Burn section."); | ||
161 | } | 160 | } |
162 | } | 161 | } |
163 | 162 | ||
@@ -168,8 +167,7 @@ extern "C" HRESULT SectionInitialize( | |||
168 | // check size of section | 167 | // check size of section |
169 | if (sizeof(BURN_SECTION_HEADER) > sectionHeader.SizeOfRawData) | 168 | if (sizeof(BURN_SECTION_HEADER) > sectionHeader.SizeOfRawData) |
170 | { | 169 | { |
171 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); | 170 | ExitWithRootFailure(hr, E_INVALIDDATA, "Failed to read section info, data too short: %u", sectionHeader.SizeOfRawData); |
172 | ExitOnRootFailure(hr, "Failed to read section info, data to short: %u", sectionHeader.SizeOfRawData); | ||
173 | } | 171 | } |
174 | 172 | ||
175 | // allocate buffer for section info | 173 | // allocate buffer for section info |
@@ -193,15 +191,19 @@ extern "C" HRESULT SectionInitialize( | |||
193 | } | 191 | } |
194 | else if (sectionHeader.SizeOfRawData > cbRead) | 192 | else if (sectionHeader.SizeOfRawData > cbRead) |
195 | { | 193 | { |
196 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); | 194 | ExitWithRootFailure(hr, E_INVALIDDATA, "Failed to read complete section info."); |
197 | ExitOnRootFailure(hr, "Failed to read complete section info."); | ||
198 | } | 195 | } |
199 | 196 | ||
200 | // validate version of section info | 197 | // validate version of section info |
201 | if (BURN_SECTION_VERSION != pBurnSectionHeader->dwVersion) | 198 | if (BURN_SECTION_VERSION != pBurnSectionHeader->dwVersion) |
202 | { | 199 | { |
203 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); | 200 | ExitWithRootFailure(hr, E_INVALIDDATA, "Failed to read section info, unsupported version: %08x", pBurnSectionHeader->dwVersion); |
204 | ExitOnRootFailure(hr, "Failed to read section info, unsupported version: %08x", pBurnSectionHeader->dwVersion); | 201 | } |
202 | |||
203 | cMaxContainers = (sectionHeader.SizeOfRawData - offsetof(BURN_SECTION_HEADER, rgcbContainers)) / sizeof(DWORD); | ||
204 | if (cMaxContainers < pBurnSectionHeader->cContainers) | ||
205 | { | ||
206 | ExitWithRootFailure(hr, E_INVALIDDATA, "Invalid section info, cContainers too large: %u", pBurnSectionHeader->cContainers); | ||
205 | } | 207 | } |
206 | 208 | ||
207 | hr = FileSizeByHandle(pSection->hSourceEngineFile, &llSize); | 209 | hr = FileSizeByHandle(pSection->hSourceEngineFile, &llSize); |