Fix a bunch of Windows bugs reported on Discord

This change addresses everything from stack smashing to %SYSTEMROOT%
breaking socket(). Issues relating to compile.com not reporting text
printed to stderr has been resolved for Windows builds.
This commit is contained in:
Justine Tunney 2023-07-28 06:17:34 -07:00
parent b0e3258709
commit 5018171fa5
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
10 changed files with 104 additions and 46 deletions

View file

@ -31,17 +31,15 @@
* @param shdr is from GetElfSectionHeaderAddress(), or null
* @return pointer to section data within image, or null if
* 1. `shdr` was null, or
* 2. `sh_size` was zero, or
* 3, `sh_type` was `SHT_NOBITS`, or
* 4. content wasn't contained within `[elf,elf+mapsize)`, or
* 5. an arithmetic overflow occurred
* 2. content wasn't contained within `[elf,elf+mapsize)`, or
* 3. an arithmetic overflow occurred
*/
void *GetElfSectionAddress(const Elf64_Ehdr *elf, // validated
size_t mapsize, // validated
const Elf64_Shdr *shdr) { // foreign
Elf64_Off last;
if (!shdr) return 0;
if (shdr->sh_size <= 0) return 0;
if (!shdr->sh_size) return elf;
if (shdr->sh_type == SHT_NOBITS) return 0;
if (ckd_add(&last, shdr->sh_offset, shdr->sh_size)) return 0;
if (last > mapsize) return 0;