Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cxbe: Fix oob section reads #652

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
thrimbor marked this conversation as resolved.
Show resolved Hide resolved

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

Expand Down