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

ensure robustness against malformed runtime class name #534

Merged
merged 2 commits into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 28 additions & 15 deletions TestComponentCSharp/Class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1274,16 +1274,16 @@ namespace winrt::TestComponentCSharp::implementation
throw hresult_not_implemented();
}

struct native_properties1 : winrt::implements<native_properties1, TestComponentCSharp::IProperties1>
TestComponentCSharp::IProperties1 Class::NativeProperties1()
{
int32_t ReadWriteProperty()
struct native_properties1 : winrt::implements<native_properties1, TestComponentCSharp::IProperties1>
{
return 42;
}
};
int32_t ReadWriteProperty()
{
return 42;
}
};

TestComponentCSharp::IProperties1 Class::NativeProperties1()
{
return winrt::make<native_properties1>();
}

Expand All @@ -1293,17 +1293,17 @@ namespace winrt::TestComponentCSharp::implementation
virtual HRESULT __stdcall GetService(int32_t* type, int32_t* service) noexcept = 0;
};

struct service_provider : winrt::implements<service_provider, WF::IInspectable, IServiceProviderInterop>
WF::IInspectable Class::ServiceProvider()
{
HRESULT __stdcall GetService(int32_t* type, int32_t* service) noexcept override
struct service_provider : winrt::implements<service_provider, WF::IInspectable, IServiceProviderInterop>
{
*service = 42;
return 0;
}
};
HRESULT __stdcall GetService(int32_t* type, int32_t* service) noexcept override
{
*service = 42;
return 0;
}
};

WF::IInspectable Class::ServiceProvider()
{
return winrt::make<service_provider>();
}

Expand All @@ -1330,5 +1330,18 @@ namespace winrt::TestComponentCSharp::implementation
DataErrorsChangedEventArgs args(detach_abi(mock), take_ownership_from_abi_t());
_dataErrorsChanged(*this, args);
}

WF::IInspectable Class::BadRuntimeClassName()
{
struct bad_runtime_classname : winrt::implements<bad_runtime_classname, WF::IInspectable>
{
hstring GetRuntimeClassName()
{
return L"BadRuntimeClassName<T>";
}
};

return winrt::make<bad_runtime_classname>();
}
}

2 changes: 2 additions & 0 deletions TestComponentCSharp/Class.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ namespace winrt::TestComponentCSharp::implementation
void ErrorsChanged(winrt::event_token const& token) noexcept;
Windows::Foundation::Collections::IIterable<Windows::Foundation::IInspectable> GetErrors(hstring const& propertyName);
void RaiseDataErrorChanged();

static Windows::Foundation::IInspectable BadRuntimeClassName();
};
}

Expand Down
2 changes: 2 additions & 0 deletions TestComponentCSharp/TestComponentCSharp.idl
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ namespace TestComponentCSharp

// INotifyDataErrorInfo
void RaiseDataErrorChanged();

static Object BadRuntimeClassName{ get; };
}

[threading(sta), marshaling_behavior(standard)]
Expand Down
5 changes: 4 additions & 1 deletion UnitTest/TestComponentCSharp_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,11 @@ public void TestCustomProjections()
IntPtr service;
serviceProvider.GetService(IntPtr.Zero, out service);
Assert.Equal(new IntPtr(42), service);
}

// Ensure robustness with bad runtime class names (parsing errors, type not found, etc)
var badRuntimeClassName = Class.BadRuntimeClassName;
Assert.NotNull(badRuntimeClassName);
}

[Fact]
public void TestKeyValuePair()
Expand Down