Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use after free in surface cache code #524

Open
X-Ryl669 opened this issue Mar 16, 2022 · 0 comments
Open

Use after free in surface cache code #524

X-Ryl669 opened this issue Mar 16, 2022 · 0 comments

Comments

@X-Ryl669
Copy link

Found this via Valgrind:

   VBitmap make_surface(
        size_t width, size_t height,
        VBitmap::Format format = VBitmap::Format::ARGB32_Premultiplied)
    {
        if (mCache.empty()) return {width, height, format};

        auto surface = mCache.back();
        surface.reset(width, height, format);

        mCache.pop_back();
        return surface;
    }

    void release_surface(VBitmap &surface) { mCache.push_back(surface); }

Here we have the sequence:

  1. VBitmap & surface = mCache.back() => we take a reference on the last element
  2. cache.pop_back(); => delete the last element in the vector
  3. return surface; => return a dangling reference on a deleted element

Instead of auto surface here, it should be VBitmap surface since auto resolve to a reference (vector::back() returns a reference on its last element)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant