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

CBL-5661 : Fix a released captured context may be used in observer callback #532

Merged
merged 1 commit into from
Apr 23, 2024

Conversation

pasin
Copy link
Contributor

@pasin pasin commented Apr 22, 2024

  • Implemented ContextManager class for retaining and mapping callback context objects with their pointer value. When getting the object back, the retained object will be returned so the object can be safely used in the callback.

  • Updated ListenerToken to use ContextManager for it’s C4QueryObserver’s callback lamda so that the callback can validate and safely use its captured context.

  • Added CBLQuery_SetListenerCallbackDelay() private API for testing the fix.

  • Updated LiteCore to 3.1.7-1 to get the fix for CBSE-16662.

@cbl-bot
Copy link

cbl-bot commented Apr 22, 2024

Code Coverage Results:

Branches Functions Instantiations Lines Regions
76.54 96.61 46.75 93.12 88.7

@pasin pasin requested review from velicuvlad, jianminzhao and bmeike and removed request for bmeike, velicuvlad and jianminzhao April 22, 2024 22:26
…llback

* Implemented ContextManager class for retaining and mapping callback context objects with their pointer value. When getting the object back, the retained object will be returned so the object can be safely used in the callback.

* Updated ListenerToken<CBLQueryChangeListener> to use ContextManager for it’s C4QueryObserver’s callback lamda so that the callback can validate and safely use its captured context.

* Added CBLQuery_SetListenerCallbackDelay() private API for testing the fix.

* Updated LiteCore to 3.1.7-1 to get the fix for CBSE-16662.
Comment on lines +91 to +96
void CBLQuery_SetListenerCallbackDelay(int delayMS) noexcept {
#ifdef DEBUG
ListenerToken<CBLQueryChangeListener>::setC4QueryObserverCallbackDelay(delayMS);
#endif
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method is not exposed for swift unless is debug (including the definition). Can we have it the same here?

#ifdef DEBUG
void CBLQuery_SetListenerCallbackDelay(int delayMS) noexcept { ... }
#endif

Copy link
Contributor Author

@pasin pasin Apr 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method needs to be exposed in the public symbols like the other methods in the private header file so that the C test program can use. I don’t want to have the public symbols points to non existing symbols. The private headers will not be available publicly and the method will do nothing in release build.

@velicuvlad velicuvlad self-requested a review April 23, 2024 14:29
@pasin pasin merged commit b89b125 into release/3.1 Apr 23, 2024
7 checks passed
@pasin pasin deleted the CBL-5661 branch April 23, 2024 14:32
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.

3 participants