Skip to content

Commit

Permalink
cxbe: Fix oob section reads
Browse files Browse the repository at this point in the history
  • Loading branch information
thrimbor committed Jul 28, 2023
1 parent da6a0bd commit cb4ec0c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 5 additions & 2 deletions tools/cxbe/Exe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "Exe.h"

#include <algorithm>
#include <memory.h>
#include <stdio.h>

Expand Down Expand Up @@ -130,10 +131,12 @@ Exe::Exe(const char *x_szFilename)

uint32 raw_size = m_SectionHeader[v].m_sizeof_raw;
uint32 raw_addr = m_SectionHeader[v].m_raw_addr;
uint32 virt_size = m_SectionHeader[v].m_virtual_size;
uint32 max_size = std::max(virt_size, raw_size);

m_bzSection[v] = new uint08[raw_size];
m_bzSection[v] = new uint08[max_size];

memset(m_bzSection[v], 0, raw_size);
memset(m_bzSection[v], 0, max_size);

if(raw_size == 0)
{
Expand Down
7 changes: 6 additions & 1 deletion tools/cxbe/Xbe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "Xbe.h"
#include "Exe.h"

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <locale.h>
Expand Down Expand Up @@ -513,8 +514,12 @@ Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail, const std::vec
printf("Xbe::Xbe: Generating Section %.04X...", v);

uint32 RawSize = m_SectionHeader[v].dwSizeofRaw;
uint32 VirtSize = m_SectionHeader[v].dwVirtualSize;
uint32 maxSize = std::max(VirtSize, RawSize);

m_bzSection[v] = new uint08[RawSize];
m_bzSection[v] = new uint08[maxSize];

memset(m_bzSection[v], 0, maxSize);

memcpy(m_bzSection[v], x_Exe->m_bzSection[v], RawSize);

Expand Down

0 comments on commit cb4ec0c

Please sign in to comment.