JusticeRage / Manalyze

A static analyzer for PE executables.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

crash in Section::get_raw_data() const

rwfpl opened this issue · comments

    FILE* f = fopen(_path.c_str(), "rb");
    if (f == nullptr || fseek(f, _pointer_to_raw_data, SEEK_SET))
    {
        fclose(f);
        return res;
    }

This condition is wrong, if (f == nullptr) will trigger fclose(nullptr) which will lead to crash.

    catch (const std::exception& e)
    {
        PRINT_ERROR << "Failed to allocate enough space for section " << *get_name() << "! (" << e.what() << ")"
            << DEBUG_INFO << std::endl;
        res->resize(0);
        return res;
    }

If I'm not mistaken, this catch & return leaks file handle f, so fclose(f) before return res should do the trick.

With attached sample you can reproduce both problems (pass: infected):
https://mega.nz/#!t5ZBzSib!pPwWSrgGl0nCGt27_wfLFv9QsYaUOKkCZIw1QlTdRMk

Thanks a lot for reporting all these issues. It's good to have someone else look at the code!
I'll fix them over the course of this week-end!

Issue 1 has been fixed (corresponding unit test).
Issue 2 has been fixed as well, and the file pointer is no longer leaked.

Thanks a lot for bringing them up!