Merge pull request #416 from liamjm/packheader_more_checks

tweaks: some extra checks on lengths
This commit is contained in:
John Reiser
2020-11-06 14:15:56 -08:00
committed by GitHub
2 changed files with 6 additions and 0 deletions
+3
View File
@@ -42,6 +42,7 @@ PackHeader::PackHeader() : version(-1), format(-1) {}
**************************************************************************/
static unsigned char get_packheader_checksum(const upx_bytep buf, int len) {
assert(len >= 4);
assert(get_le32(buf) == UPX_MAGIC_LE32);
// printf("1 %d\n", len);
buf += 4;
@@ -92,6 +93,8 @@ int PackHeader::getPackHeaderSize() const {
**************************************************************************/
void PackHeader::putPackHeader(upx_bytep p) {
// NOTE: It is the caller's responsbility to ensure the buffer p has
// sufficient space for the header.
assert(get_le32(p) == UPX_MAGIC_LE32);
if (get_le32(p + 4) != UPX_MAGIC2_LE32) {
// fprintf(stderr, "MAGIC2_LE32: %x %x\n", get_le32(p+4), UPX_MAGIC2_LE32);
+3
View File
@@ -241,6 +241,9 @@ int __acc_cdecl_qsort le64_compare_signed(const void *e1, const void *e2) {
int find(const void *b, int blen, const void *what, int wlen) {
if (b == NULL || blen <= 0 || what == NULL || wlen <= 0)
return -1;
// Fast exit if the wanted string is longer than the buffer.
if (wlen > blen)
return -1;
int i;
const unsigned char *base = (const unsigned char *) b;