mirror of
https://github.com/opnsense/src.git
synced 2026-05-28 04:12:45 -04:00
crunchide: add basic string table sanity checks
Reported by: Coverity Scan CID: 978805, 980919 Sponsored by: The FreeBSD Foundation
This commit is contained in:
parent
6508929bc2
commit
e52f97153a
1 changed files with 13 additions and 6 deletions
|
|
@ -321,11 +321,14 @@ ELFNAMEEND(hide)(int fd, const char *fn)
|
|||
*/
|
||||
|
||||
/* load section string table for debug use */
|
||||
if ((shstrtabp = xmalloc(xewtoh(shstrtabshdr->sh_size), fn,
|
||||
"section string table")) == NULL)
|
||||
if ((size = xewtoh(shstrtabshdr->sh_size)) == 0)
|
||||
goto bad;
|
||||
if ((shstrtabp = xmalloc(size, fn, "section string table")) == NULL)
|
||||
goto bad;
|
||||
if ((size_t)xreadatoff(fd, shstrtabp, xewtoh(shstrtabshdr->sh_offset),
|
||||
xewtoh(shstrtabshdr->sh_size), fn) != xewtoh(shstrtabshdr->sh_size))
|
||||
size, fn) != size)
|
||||
goto bad;
|
||||
if (shstrtabp[size - 1] != '\0')
|
||||
goto bad;
|
||||
|
||||
/* we need symtab, strtab, and everything behind strtab */
|
||||
|
|
@ -346,7 +349,8 @@ ELFNAMEEND(hide)(int fd, const char *fn)
|
|||
strtabidx = i;
|
||||
if (layoutp[i].shdr == symtabshdr || i >= strtabidx) {
|
||||
off = xewtoh(layoutp[i].shdr->sh_offset);
|
||||
size = xewtoh(layoutp[i].shdr->sh_size);
|
||||
if ((size = xewtoh(layoutp[i].shdr->sh_size)) == 0)
|
||||
goto bad;
|
||||
layoutp[i].bufp = xmalloc(size, fn,
|
||||
shstrtabp + xewtoh(layoutp[i].shdr->sh_name));
|
||||
if (layoutp[i].bufp == NULL)
|
||||
|
|
@ -356,10 +360,13 @@ ELFNAMEEND(hide)(int fd, const char *fn)
|
|||
goto bad;
|
||||
|
||||
/* set symbol table and string table */
|
||||
if (layoutp[i].shdr == symtabshdr)
|
||||
if (layoutp[i].shdr == symtabshdr) {
|
||||
symtabp = layoutp[i].bufp;
|
||||
else if (layoutp[i].shdr == strtabshdr)
|
||||
} else if (layoutp[i].shdr == strtabshdr) {
|
||||
strtabp = layoutp[i].bufp;
|
||||
if (strtabp[size - 1] != '\0')
|
||||
goto bad;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue