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

dnsdist: Increment the DOHUnit ref count when it's set in the IDState #8471

Merged
merged 2 commits into from Oct 26, 2019

Conversation

@rgacogne
Copy link
Member

@rgacogne rgacogne commented Oct 25, 2019

Short description

We need to increment the reference counter even before sending the
query to the backend, as soon as we copy a reference into the IDState.
Because:

  • that makes sense anyway, we are storing a new copy ;
  • otherwise, in the unlikely event where we reuse the IDState before the query has been sent to the backend we might free the DOHUnit before the reference counter has been incremented and cause a double-free.

This is why we love smart pointers, too bad that we need to deal with raw C pointers a bit in that code..

Checklist

I have:

  • read the CONTRIBUTING.md document
  • compiled this code
  • tested this code
  • included documentation (including possible behaviour changes)
  • documented the code
  • added or modified regression test(s)
  • added or modified unit test(s)
We need to increment the reference counter even before sending the
query to the backend, as soon as we copy a reference into the IDState.
Because:
- that makes sense anyway, we are storing a new copy ;
- otherwise, in the unlikely event where we reuse the IDState before
  the query has been sent to the backend we might free the DOHUnit
  before the reference counter has been incremented and cause a
  double-free.
It was based on the reference counter used for the DOHAcceptContext
where thread safety was never an issue because those objects are
not shared between threads, but DOHUnit are.
@rgacogne rgacogne merged commit 2393dd9 into PowerDNS:master Oct 26, 2019
27 checks passed
@rgacogne rgacogne deleted the ddist-du-refcount-ids branch Oct 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

1 participant