ptitSeb / box64

Box64 - Linux Userspace x86_64 Emulator with a twist, targeted at ARM64 Linux devices
https://box86.org
MIT License
3.9k stars 287 forks source link

Maybe a mistake in ELF parser #1493

Closed SineStriker closed 6 months ago

SineStriker commented 6 months ago

I know it

https://github.com/ptitSeb/box64/blob/main/src/elfs/elfparser.c#L125
elfheader_t *h = box_calloc(1, sizeof(elfheader_t));
// ...
h->numSHEntries = header.e_shnum;
// ...
if(header.e_shentsize && header.e_shnum) {
    // special cases for nums
    if(h->numSHEntries == 0) {                                    // THIS BRANCH IS IMPOSSIBLE TO BE EXECUTED!!!
        printf_dump(LOG_DEBUG, "Read number of Sections in 1st Section\n");
        // read 1st section header and grab actual number from here
        // ...
        h->numSHEntries = section.sh_size;
    }
}

h->numSHEntries has been stored with value of e_shnum, only when e_shnum is non-zero will the outter branch be executed, then the h->numSHEntries must be non-zero as well, then the inner branch will never be executed.

ptitSeb commented 6 months ago

You are correct, I'll improve this part.