Skip to content

Commit

Permalink
Beware overlap when rebuildImports
Browse files Browse the repository at this point in the history
Based on a hint from a little bird.
	modified:   pefile.cpp
  • Loading branch information
jreiser committed Sep 20, 2020
1 parent 107cd48 commit 1499226
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/pefile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ static void xcheck(size_t poff, size_t plen, const void *b, size_t blen)
#define omemset(a,b,c) OCHECK(a,c), memset(a,b,c)
#define imemcpy(a,b,c) ICHECK(a,c), memcpy(a,b,c)
#define omemcpy(a,b,c) OCHECK(a,c), memcpy(a,b,c)
#define omemmove(a,b,c) OCHECK(a,c), memmove(a,b,c)


/*************************************************************************
Expand Down Expand Up @@ -2814,16 +2815,14 @@ void PeFile::rebuildImports(upx_byte *& extrainfo,
if (inamespos)
{
// now I rebuild the dll names
OCHECK(dllnames, dlen + 1);
strcpy(dllnames, dname);
omemcpy(dllnames, dname, dlen + 1);
im->dllname = ptr_diff(dllnames,Obuf);
//;;;printf("\ndll: %s:",dllnames);
dllnames += dlen + 1;
}
else
{
OCHECK(Obuf + im->dllname, dlen + 1);
strcpy(Obuf + im->dllname, dname);
omemcpy(Obuf + im->dllname, dname, dlen + 1);
}
im->iat = iatoffs;
if (set_oft)
Expand All @@ -2847,8 +2846,8 @@ void PeFile::rebuildImports(upx_byte *& extrainfo,
}
else
{
OCHECK(Obuf + (*newiat + 2), ilen + 1);
strcpy(Obuf + (*newiat + 2), p);
// Beware overlap!
omemmove(Obuf + (*newiat + 2), p, ilen + 1);
}
p += ilen;
}
Expand Down

0 comments on commit 1499226

Please sign in to comment.