You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Castle allows to rewrite read-only parameters (in modifier) #369
The issue happens because value is passed by ref, so technically it's possible to rewrite the value. However, like Roslyn, Castle should not allow to rewrite the value via API.
We could additionally probe whether (parameters[i].Attributes & (ParameterAttributes.In | ParameterAttributes.Out)) == ParameterAtteibutes.In, and if so, not write back the argument value.
(AFAIK, in parameters are marked in various ways, depending on the situation, but the IL [in] attribute should always be set. IIRC it is not set for regular by-value parameters unless maybe in COM interfaces.)
@jonorossi Could you please release this bug fix on NuGet? At the NSubstitute side I would like to do the following:
Consume this version as a required to guarantee safety.
Write unit tests that our generated delegates propagate the in modifier correctly. To do that I would like to confirm that value is indeed read-only, but current I cannot write such a test.
I believe it should be fine for Castle.Core to publish a bugfix release with increased revision.
Activity
stakx commentedon Jun 11, 2018
Yes, this appears to be a problem. I believe we should add a check for
in-ness of parameters here:Core/src/Castle.Core/DynamicProxy/Generators/GeneratorUtil.cs
Line 38 in 39457da
We could additionally probe whether
(parameters[i].Attributes & (ParameterAttributes.In | ParameterAttributes.Out)) == ParameterAtteibutes.In, and if so, not write back the argument value.(AFAIK,
inparameters are marked in various ways, depending on the situation, but the IL[in]attribute should always be set. IIRC it is not set for regular by-value parameters unless maybe in COM interfaces.)stakx commentedon Jun 11, 2018
@zvirja - I've had a free afternoon and thought I'd tackle this. You were spot on with where the fix needs to go. 👍
zvirja commentedon Jun 13, 2018
@jonorossi Could you please release this bug fix on NuGet? At the NSubstitute side I would like to do the following:
inmodifier correctly. To do that I would like to confirm that value is indeed read-only, but current I cannot write such a test.I believe it should be fine for
Castle.Coreto publish a bugfix release with increased revision.Thanks.