fix null deref when pointer dependency passed as lvalue to sm ctor (#485)#673
Merged
kris-jusiak merged 2 commits intoMay 24, 2026
Conversation
9f0d2e3 to
7c996d3
Compare
…ssue boost-ext#485) When a T* dependency is passed as an lvalue to sm<M>{ptr}, forwarding reference deduction binds TDeps as T*& (reference-to-pointer). The pool init constructor then creates pool<T*&> as the input pool. The stripping logic: remove_const_t<remove_reference_t<remove_pointer_t<T*>>> strips T* to T and calls try_get<T> on pool<T*&>. The existing try_get overloads only cover pool_type<T*> and pool_type<const T*>; there is no overload for pool_type<T*&>, so the call falls through to the variadic catch-all which returns missing_ctor_parameter<T>{}. That converts to a null T* (or null const T*), so every action/guard taking a pointer dependency receives nullptr and dereferences it — crash. Fix: add two try_get overloads that match reference-to-pointer types: template <class T> T* try_get(const pool_type<T*&>* object) template <class T> const T* try_get(const pool_type<const T*&>* object) These extract the stored pointer value from the reference-wrapping pool slot. The T& (reference) case was already handled correctly and is unaffected. Regression tests added in test/ft/dependencies.cpp: pointer_dep_lvalue_not_null — action takes Dep*, sm{Dep* lvalue} const_pointer_dep_lvalue_not_null — action takes const Dep*, sm{Dep* lvalue} Fixes boost-ext#485.
7c996d3 to
c990fc4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a
T*dependency is passed as an lvalue tosm<M>{ptr}, C++ forwarding reference deduction bindsTDepsasT*&(reference-to-pointer). The pool init constructor then builds an input pool of typepool<T*&>.The stripping logic in the pool init constructor:
strips
T*→T, then callstry_get<T>onpool<T*&>. The existingtry_getoverloads only matchpool_type<T*>andpool_type<const T*>— there is no overload forpool_type<T*&>, so the call falls through to the variadic catch-all and returnsmissing_ctor_parameter<T>{}. That silently converts to a null pointer. Every action or guard that takes a pointer dependency then receivesnullptrand dereferences it → crash / assertion failure.Reproduction
The same bug affects
Dep*(non-const) action parameters.Fix
Add two
try_getoverloads that match reference-to-pointer pool slots:These extract the stored pointer from the reference-wrapping slot. The
T&(reference dependency) case already worked correctly and is unaffected.Tests
Regression tests added in
test/ft/dependencies.cpp:pointer_dep_lvalue_not_null— action takesDep*, SM constructed withDep*lvalueconst_pointer_dep_lvalue_not_null— action takesconst Dep*, SM constructed withDep*lvalueExisting test suite passes without modification.
Fixes #485.