The Wayback Machine - https://web.archive.org/web/20260109115002/https://github.com/github/codeql/pull/4780
Skip to content

Conversation

@hvitved
Copy link
Contributor

@hvitved hvitved commented Dec 4, 2020

In nested finally blocks such as

void M12(bool b1, bool b2)
{
    try
    {
        try
        {
            if (b1)
                throw new ExceptionA();
        }
        finally
        {
            try
            {
                if (b2)
                    throw new ExceptionA();
            }
            finally
            {
                Console.WriteLine("Inner finally");
            }
        }
        Console.WriteLine("Mid finally");
    }
    finally
    {
        Console.WriteLine("Outer finally");
    }
    Console.WriteLine("Done");
}

we were unable to distinguish whether the inner finally block inherited an ExceptionA completion from the outer throw or the inner throw. The (somewhat surprising) effect was that we were missing a CFG edge (highlighted):

cfg

The solution is to record information about the nesting level of inherited completions, which enables us to distinguish the two cases. Commit-by-commit review is encouraged.

https://jenkins.internal.semmle.com/job/Changes/job/CSharp-Differences/670/

@github-actions github-actions bot added the C# label Dec 4, 2020
@hvitved hvitved force-pushed the csharp/cfg/nested-finally branch from 71b86c7 to 3531dde Compare December 5, 2020 19:16
@hvitved hvitved marked this pull request as ready for review December 7, 2020 08:40
@hvitved hvitved requested a review from a team as a code owner December 7, 2020 08:40
Copy link
Contributor

@tamasvajk tamasvajk left a comment

Choose a reason for hiding this comment

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

LGTM

@hvitved hvitved merged commit 249eea9 into github:main Dec 14, 2020
@hvitved hvitved deleted the csharp/cfg/nested-finally branch December 14, 2020 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2 participants