[csharp] Delegate propagation fails #20255
-
I’m analyzing a DLL and encountered a code pattern that I’m having trouble modeling with CodeQL. Below is a simplified example to illustrate the issue: namespaceConsoleApp1{// 1. Define the delegate with one input and one out parameterdelegatevoidSimpleDelegate(stringinput,outstringoutput);// 2. A method that matches the delegate signatureclassHandler{publicstaticvoidProcess(stringinput,outstringoutput){output="Processed: "+input;}}// 3. Class that stores and retrieves the delegateclassDelegateRegistry{publicstaticreadonlyDictionary<string,SimpleDelegate>Registry=newDictionary<string,SimpleDelegate>();publicstaticvoidRegister(stringkey,SimpleDelegatedel){Registry[key]=del;}}internalclassDelegatePoc{staticvoidPoc(){stringsource="source";SimpleDelegatesimpleDelegate=newSimpleDelegate(Handler.Process);/// Register the delegateDelegateRegistry.Register("key",simpleDelegate);// Fetch and callif(DelegateRegistry.Registry.TryGetValue("key",outSimpleDelegatedel)){stringresult;del(source,outresult);Console.WriteLine(result);}}}}Tracking the I don't know why it can't follow further or find the |
BetaWas this translation helpful?Give feedback.
Replies: 2 comments 2 replies
-
Hi @Hug0Vincent, I've asked the team to have a look. |
BetaWas this translation helpful?Give feedback.
-
Hi. Thanks for your question. This is a known limitation of how we resolve delegate calls (we do not track delegates stored in collections). If it instead had been classDelegateRegistry{publicstaticreadonlySimpleDelegated=null;publicstaticvoidRegister(SimpleDelegatedel){d=del;}}then it ought to work (we do track delegates stored in fields). I have been wanting to improve this for some time, but it has not yet been a priority. |
BetaWas this translation helpful?Give feedback.
Hi.
Thanks for your question. This is a known limitation of how we resolve delegate calls (we do not track delegates stored in collections). If it instead had been
then it ought to work (we do track delegates stored in fields).
I have been wanting to improve this for some time, but it has not yet been a priority.