-
Notifications
You must be signed in to change notification settings - Fork 5
Description
quoting from an email i received from Trevor Gray:
There is a potential stack-use-after-scope in
execution::transform_senderwithexecution::default_domain::transform_sender.I'll give an example of the problem using
starts_onwith thedefault_domain.
starts_ondefines atransform_sendersoexecution::transform_senderwill expand to:return transform_sender( dom, dom.transform_sender(std::forward<Sndr>(sndr), env...), env...);
domis thedefault_domain
sndrisstarts_onExecution flow:
dom.transform_sender(std::forward<Sndr>(sndr), env...)usesdefault_domainto invokestart_on'stransform_sender. The return type isT(whereTis alet_valuesender)transform_sender(dom, declval<T>(), env...)is then run which usesdefault_domainto just returnstd::forward<T>(t).This means the value returned from the entire expression is
T&&which a reference to a temporary variable in the frame oftransform_senderwhich is no longer valid after the return
Discussion
in the reference implementation, this scenario does not create a dangling reference because its implementation of default_domain::transform_sender does not conform to the spec. by default, it returns an rvalue sender as a prvalue instead of an xvalue as the spec requires.
the fix is for the spec to follow suit and return prvalues when an xvalue would otherwise be returned.
Proposed resolution
Change [exec.domain.default]/p2 should be changed from:
- Let
ebe the expressiontag_of_t<Sndr>().transform_sender(std::forward<Sndr>(sndr), env...)
if that expression is well-formed; otherwise,std::forward<Sndr>(sndr).
to:
- Let
ebe the expressiontag_of_t<Sndr>().transform_sender(std::forward<Sndr>(sndr), env...)
if that expression is well-formed; otherwise,static_cast<Sndr>(std::forward<Sndr>(sndr)).