Skip to content
Permalink
Browse files
Beware overlap when rebuildImports
Based on a hint from a little bird.
	modified:   pefile.cpp
  • Loading branch information
jreiser committed Sep 20, 2020
1 parent 107cd48 commit 14992260c60b8d6677a677a9cdfae98b11353df7
Showing 1 changed file with 5 additions and 6 deletions.
@@ -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)


/*************************************************************************
@@ -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)
@@ -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;
}

0 comments on commit 1499226

Please sign in to comment.