src: silence some bogus GitHub CodeQL warnings; add MemBuffer "+" overload

This commit is contained in:
Markus F.X.J. Oberhumer
2022-09-17 07:51:42 +02:00
parent 63298ebd6d
commit b4cb9f8b2f
5 changed files with 42 additions and 24 deletions
+7 -5
View File
@@ -62,6 +62,8 @@ unsigned char PackLinuxElf::o_shstrtab[] = { \
/*offset 20*/ '.','s','h','s','t','r','t','a','b','\0'
};
#define usizeof(x) ((unsigned) sizeof(x))
static unsigned
umin(unsigned a, unsigned b)
{
@@ -267,14 +269,14 @@ PackLinuxElf32::PackLinuxElf32help1(InputFile *f)
}
if (0==e_phnum) throwCantUnpack("0==e_phnum");
e_phoff = get_te32(&ehdri.e_phoff);
unsigned const last_Phdr = e_phoff + e_phnum * sizeof(Elf32_Phdr);
unsigned const last_Phdr = e_phoff + e_phnum * usizeof(Elf32_Phdr);
if (last_Phdr < e_phoff // wrap-around
|| e_phoff != sizeof(Elf32_Ehdr) // must be contiguous
|| (unsigned long)file_size < last_Phdr) {
throwCantUnpack("bad e_phoff");
}
e_shoff = get_te32(&ehdri.e_shoff);
unsigned const last_Shdr = e_shoff + e_shnum * sizeof(Elf32_Shdr);
unsigned const last_Shdr = e_shoff + e_shnum * usizeof(Elf32_Shdr);
if (last_Shdr < e_shoff // wrap-around
|| (e_shnum && e_shoff < last_Phdr)
|| (unsigned long)file_size < last_Shdr) {
@@ -346,7 +348,7 @@ off_t PackLinuxElf::pack3(OutputFile *fo, Filter &ft) // return length of output
fo->write(&zero, t);
len += t; // force sz_pack2 (0 mod 8) [see below]
set_te32(&disp, sz_elf_hdrs + sizeof(p_info) + sizeof(l_info) +
set_te32(&disp, sz_elf_hdrs + usizeof(p_info) + usizeof(l_info) +
(!!xct_off & !!opt->o_unix.android_shlib)); // |1 iff android shlib
fo->write(&disp, sizeof(disp)); // offset(b_info)
len += sizeof(disp);
@@ -1182,7 +1184,7 @@ PackLinuxElf32::buildLinuxLoader(
struct b_info h; memset(&h, 0, sizeof(h));
unsigned fold_hdrlen = 0;
cprElfHdr1 const *const hf = (cprElfHdr1 const *)fold;
fold_hdrlen = umax(0x80, sizeof(hf->ehdr) +
fold_hdrlen = umax(0x80, usizeof(hf->ehdr) +
get_te16(&hf->ehdr.e_phentsize) * get_te16(&hf->ehdr.e_phnum) +
sizeof(l_info) );
h.sz_unc = ((szfold < fold_hdrlen) ? 0 : (szfold - fold_hdrlen));
@@ -1252,7 +1254,7 @@ PackLinuxElf64::buildLinuxLoader(
struct b_info h; memset(&h, 0, sizeof(h));
unsigned fold_hdrlen = 0;
cprElfHdr1 const *const hf = (cprElfHdr1 const *)fold;
fold_hdrlen = umax(0x80, sizeof(hf->ehdr) +
fold_hdrlen = umax(0x80, usizeof(hf->ehdr) +
get_te16(&hf->ehdr.e_phentsize) * get_te16(&hf->ehdr.e_phnum) +
sizeof(l_info) );
h.sz_unc = ((szfold < fold_hdrlen) ? 0 : (szfold - fold_hdrlen));