Skip to content

Fix heap corruption#109

Open
mlederhi wants to merge 1 commit into
artyom-beilis:masterfrom
mlederhi:fix_heap_corruption
Open

Fix heap corruption#109
mlederhi wants to merge 1 commit into
artyom-beilis:masterfrom
mlederhi:fix_heap_corruption

Conversation

@mlederhi

Copy link
Copy Markdown

in the case where size is between page_size and 2 * page_size.

@artyom-beilis

Copy link
Copy Markdown
Owner

Can you give a case it fails? How it fixes the issue? I tried setting small page sizes and it all works.

Also I don't see the bug here. The idea is following if it is a long string allocate a separate page for it, otherwise use paged pool.

@artyom-beilis

Copy link
Copy Markdown
Owner

I also rerun some cases with small buffer size with valgrind to see if anythonig shows up and it does not.

Can you please explain the fix and what it fixes.

@artyom-beilis

Copy link
Copy Markdown
Owner

The reason for size * 2 - is to prevent wasting too much memory for large strings.

@mlederhi

Copy link
Copy Markdown
Author

The problem is the case were the size is between page size and 2 * page size.

It's too small to allocate an own page with the correct size ( > 2 * page size case).

Then depending on the size it allocates a new page or uses an existing page. But since the size is > page size it always writes the string out of bounds because a page has a maximum size of page_size and that is smaller than size.

@mlederhi

Copy link
Copy Markdown
Author

Note that I don't know why it worked with CppCMS 1.2.1 (same code in string_map.h). But with CppCMS 2.0.1 we started experiencing problems in only one of our applications. I found the origin of the problem with Valgrind's memcheck.

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

Successfully merging this pull request may close these issues.

2 participants