8000 Fixes #476: Accessing freed memory in fastboot.c by henrik-haltian · Pull Request #477 · nxp-imx/mfgtools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fixes #476: Accessing freed memory in fastboot.c #477

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
29 changes: 20 additions & 9 deletions libuuu/fastboot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,18 @@ int FBFlashCmd::run(CmdCtx *ctx)
pb = pin->request_data(0, sizeof(sparse_header));
if (!pb)
return -1;
sparse_header * pfile = (sparse_header *)pb->data();

__le16 file_hdr_sz;
__le32 blk_sz;
__le32 total_blks;
__le32 total_chunks;
{
sparse_header * pfile = (sparse_header *)pb->data();
file_hdr_sz = pfile->file_hdr_sz;
blk_sz = pfile->blk_sz;
total_blks = pfile->total_blks;
total_chunks = pfile->total_chunks;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does below change work?

sparse_header header = *(sparse_header *)pb->data();
sparse_header * pfile = &header;

if (!SparseFile::is_validate_sparse_file(pb->data(), sizeof(sparse_header)))
{
Expand All @@ -833,14 +844,14 @@ int FBFlashCmd::run(CmdCtx *ctx)

uuu_notify nt;
nt.type = uuu_notify::NOTIFY_TRANS_SIZE;
nt.total = pfile->total_blks;
nt.total = total_blks;
call_notify(nt);

sf.init_header(pfile->blk_sz, max / pfile->blk_sz);
sf.init_header(blk_sz, max / blk_sz);
startblock = 0;
pos = pfile->file_hdr_sz;
pos = file_hdr_sz;

for(size_t nblk=0; nblk < pfile->total_chunks && pos <= pin->size(); nblk++)
for(size_t nblk=0; nblk < total_chunks && pos <= pin->size(); nblk++)
{
pb = pin->request_data(pos, sizeof(chunk_header_t));
if (!pb)
Expand All @@ -864,7 +875,7 @@ int FBFlashCmd::run(CmdCtx *ctx)
if (flash(&fb, sf.m_data.data(), sf.m_data.size()))
return -1;

sf.init_header(pfile->blk_sz, max / pfile->blk_sz);
sf.init_header(blk_sz, max / blk_sz);

chunk_header_t ct;
ct.chunk_type = CHUNK_TYPE_DONT_CARE;
Expand All @@ -889,14 +900,14 @@ int FBFlashCmd::run(CmdCtx *ctx)
else
{
size_t off = sz + sizeof(chunk_header_t);
startblock += sz / pfile->blk_sz;
startblock += sz / blk_sz;

do
{
if (flash(&fb, sf.m_data.data(), sf.m_data.size()))
return -1;

sf.init_header(pfile->blk_sz, max / pfile->blk_sz);
sf.init_header(blk_sz, max / blk_sz);

chunk_header_t ct;
ct.chunk_type = CHUNK_TYPE_DONT_CARE;
Expand All @@ -908,7 +919,7 @@ int FBFlashCmd::run(CmdCtx *ctx)

sz = sf.push_raw_data(pb->data() + off, pb->size() - off);
off += sz;
startblock += sz / pfile->blk_sz;
startblock += sz / blk_sz;

uuu_notify nt;
nt.type = uuu_notify::NOTIFY_TRANS_POS;
Expand Down
0