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

Fixed null access #645

Closed
wants to merge 1 commit into from
Closed

Fixed null access #645

wants to merge 1 commit into from

Conversation

zii-dmg
Copy link

@zii-dmg zii-dmg commented Jan 20, 2023

parentContext was checked for null after access to parentContext.Handler and .ReleasePolicy

`parentContext` was checked for null after access to `parentContext.Handler` and `.ReleasePolicy`
@jonorossi
Copy link
Member

We really need a unit test for a case where the parent context is null. If this is a bug, it hasn't surfaced in nearly 20 years.

@Toxantron
Copy link

@zii-dmg could you eloborate in which situation the parentContext was `null``? But I agree it is inconsistent to check for null after already accessing the members.

@zii-dmg
Copy link
Author

zii-dmg commented Jul 26, 2023

Found by static analyzer.

@zii-dmg
Copy link
Author

zii-dmg commented Jul 26, 2023

It's public API. Anyone can pass null and will get NullReferenceException instead of ArgumentNullException.

@@ -67,7 +67,7 @@ public class CreationContext :
/// <param name = "parentContext"> The parent context. </param>
/// <param name = "propagateInlineDependencies"> When set to <c>true</c> will clone <paramref name = "parentContext" /> <see cref = "AdditionalArguments" /> . </param>
public CreationContext(Type requestedType, CreationContext parentContext, bool propagateInlineDependencies)
: this(parentContext.Handler, parentContext.ReleasePolicy, requestedType, null, null, parentContext)
: this(parentContext?.Handler, parentContext?.ReleasePolicy, requestedType, null, null, parentContext)
Copy link
Member

Choose a reason for hiding this comment

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

The problem with doing this is that you call the other constructor passing a null IHandler and IReleasePolicy which isn't valid.

You'll find that Windsor likely has a bunch of these "bugs" that aren't hurting anyone because Windsor's original design was to be completely open with everything marked public, you can see ResolutionContext in the same file is public with no checking, but is never created by users. We've been slowly closing things with Castle DynamicProxy because we needed to to keep the public API sane and make changes, however Windsor is still completely open.

I'd like to see Windsor enable nullable reference types, however accepting this pull request would mean that the other constructor needs to accept null and run to completion to then run this constructor which throws.

@zii-dmg zii-dmg closed this by deleting the head repository May 23, 2024
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.

None yet

3 participants