I'm writing some c# that will load a third party assembly.
If the third party decided to be malicious, they could write a recursive function that would end up in a StackOverflowException, bringing down my application.
Is it possible to detect a recursive function?
Update: For undesirable sitations like while(true), or for(;;), I already have a solution. Essentially, I run the third party code in a separate thread, and if the thread takes longer than a fixed duration, I pull the plug. This doesn't work well with recursion since the stack limit is reached extremely quickly.
Update: Perhaps I've misrepresented the solution that I'm after. If I end up getting a lot of intentionally malicious code, I'll change the application to run the third party code in a separate process. However at this stage, I'm assuming that the code will only cause problems because it's poorly written.
Accepted Answer I've decided that the best approach would be to run the third party libraries in a separate process. I can have multiple instances of the processes running, and even do a sort of load balancing of my third party libraries across the processes. If malicious code is executed that kills one of the processes, I should be able to detect which library killed it, mark that library as malicious, and relaunch the process with all of the non-malicious libraries.
Thanks for everyone's great suggestions!