Symbolic Execution Explained: Finding Bugs in Complex Code Paths
summary
Sonar’s static analyzer uses symbolic execution to simulate execution paths with symbolic ranges (e.g., remainder 0..9 or -9..0) and flags contradictions; it finds a real bug in .NET’s SqlMoney rounding where C#’s negative remainder in C# makes the “round up if remainder ≥ 5” branch unreachable. The engine produces a path map, reports the unreachable branch detected, and the issue is reported to the repo — the analyzer successfully exposes the root cause.
AI-written summary · about
chapters (27)
- 0:00Introduction
- 0:27How Conditionals Create Alternate Code Execution Paths
- 1:03Using Symbolic Execution to Map Possible Code Paths
- 1:22Real Bug Example from the .NET Runtime
- 1:56SqlMoney Conversion and Rounding Logic Explained
- 3:01How Modulo Behavior Introduces a Hidden Bug
- 4:27Why C# Modulo Keeps the Negative Sign
- 4:47Example Demonstrating Incorrect Rounding Behavior
- 5:34Why This Type of Bug Is Hard to Detect
- 5:51Static Analyzer Detects Unreachable Code Paths
- 6:44How Symbolic Execution Works in Static Code Analysis
- 7:18Symbolic Values Represent Input Ranges
- 8:03Engine Simulates Different Execution Paths
- 8:47First Scenario: Positive Value Execution Path
- 9:18Remainder Range Becomes 0 to 9
- 10:07Branch Where Remainder Is Less Than 5
- 10:47Branch Where Remainder Is Greater Than or Equal to 5
- 11:17Inner Condition Always True in This Scenario
- 11:53Second Scenario: Negative Value Execution Path
- 13:15Negative Modulo Produces a Negative Remainder
- 13:52Why the Condition “Remainder ≥ 5” Becomes Impossible
- 14:22Missing Execution Scenario Reveals the Bug
- 15:15Analyzer Detects the Unreachable Code Path
- 16:16Root Cause: Negative Modulo Behavior in C#
- 16:33Static Analysis Also Detects Null Dereference Risks
- 16:45Detecting Index Out-of-Bounds Errors Automatically
- 16:56How Symbolic Execution Finds Subtle Software Bugs
related talks
01h 01mSymbolic Execution in .NET
52mFinding Bugs Using Path-Sensitive Static Analysis
55mCode Analysis with Zero False Positives in Java
20mDerivative-Guided Symbolic Execution
31mSound Symbolic Execution via Abstract Interpretation and its Application to Sec...
38mStatic Code Analysis - A Behind-the-scenes Look
14mCompatible Branch Coverage Driven Symbolic Execution for Efficient Bug Finding
33mSymbolic value-flow static analysis:deep,precise,complete modeling of Ethereum smartcontracts
