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

Replaced working with bson utf8 string inside db_mongodb_convert_bson function #1508

Closed
wants to merge 3 commits into from

Conversation

tiglat
Copy link
Contributor

@tiglat tiglat commented Apr 24, 2018

Pre-Submission Checklist

  • Commit message has the format required by CONTRIBUTING guide
  • Commits are split per component (core, individual modules, libs, utils, ...)
  • Each component has a single commit (if not, squash them into one commit)
  • No commits to README files for modules (changes must be done to docbook files
    in doc/ subfolder, the README file is autogenerated)

Type Of Change

  • Small bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds new functionality)
  • Breaking change (fix or feature that would change existing functionality)

Checklist:

Description

During query operations string fields inside result structure db1_res_t could be corrupted because of incorrect usage of bson memory.

This issue is reproduced when we need to read more than 150 documents from the database.

Firstly bson_iter_utf8 function returns pointer to memory which is allocated by bson library. It looks like this memory is used multiple times (some kind of circular buffer). So the data must be copied into Kamailio memory instead storing that pointer. The original pointer becomes invalid after some time.

Secondly, this pointer must not be freed by the caller of bson_iter_utf8. At the current version bson allocated pointer is freed by Kamailio function pkg_free like it is was allocated by pkg_malloc.

miconda added a commit that referenced this pull request Apr 25, 2018
- the bson iterator invalidates or reuses the memory after several interations
- initial patch by Konstantin Poliakov <k.polyakov@mightycall.com>, GH #1508
@miconda
Copy link
Member

miconda commented Apr 25, 2018

Thanks!

I applied a slightly different patch to check the return code of converting the UTF8 value to internal db val with cloning.

For future PRs, format the git commit lines as per contributing guide:

It makes merging straightforward via web interface, without manual patching to adjust the commit message.

@miconda miconda closed this Apr 25, 2018
miconda added a commit that referenced this pull request Apr 25, 2018
- the bson iterator invalidates or reuses the memory after several interations
- initial patch by Konstantin Poliakov <k.polyakov@mightycall.com>, GH #1508

(cherry picked from commit 1ef70d6)
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.

None yet

2 participants