How to Secure C and C++ Code Using Fuzz Testing Contents 04 How Companies Secure С/С++ Today 06 What is Fuzz Testing 07 How Fuzzing Helps With С/С++ Security 08 Good Use Cases for Fuzz Testing 09 What Bugs You Can Find With Fuzzing in C/C++ 10 How to Trigger Memory Corruptions With Fuzzing? 12 Good Fuzz Testing Tools 13 Setting Up Fuzzing for Your Project 15 — 02 Introducing Spark: The Next Generation of Fuzzing Assistance Why secure C/C++ C and C++ remain widely used across critical industries due to their performance, efficiency, and low-level system access. These languages are the backbone of Operating Systems (Windows, Linux, macOS Automotive Software (ECU firmware, ADAS, vehicle communication protocols Medical Devices (life-support systems, imaging software, diagnostics Aerospace & Defense (real-time control systems, avionics software Financial Services (high-frequency trading systems, cryptographic libraries Embedded & IoT Systems (industrial control systems, consumer electronics) At the same time, C and C++ are notorious for being bug-prone. In fact, one in four issues of the Top 25 Most Dangerous Software Weaknesses is related to C or C++. Memory corruption bugs remain among the most dangerous vulnerabilities One caused the CrowdStrike IT Outage in 2024. Three — Out-of-Bounds Write, Out-of-Bounds Read, and Use After Free — are in the Top 10 Most Dangerous Weaknesses. Even though most companies implement security practices such as linters, static analysis, and penetration testing, many critical vulnerabilities and bugs still make it into production. In this white paper, we explore how C/C++ code can be secured using an advanced security technique — white-box fuzz testing. — 03 How Companies Secure C/C++ Today Testing Effectiveness Testing Approach SDLC Stage According to Forrester’s research, 94% of companies use static analysis. Nonetheless, penetration testers and attackers find vulnerabilities in tested software. Code Build Test Deploy Static Analysis Pen Testing Scans code for known issues without actually executing it Manually simulated attack from outside by authorized tester Operate False Positives Discovered Vulnerabilities - Low complexity Discovered Vulnerabilities - High complexity While static analysis has undeniable advantages — such as immediate feedback loops in the IDE (since no compilation is required) and helping achieve compliance with guidelines like MISRA — it also has significant limitations. — 04 There are certain types of issues in C/C++ code that static analysis alone may struggle to detect or miss entirely. Examples include: • Runtime or dynamic behavior issues • Input-dependent flaws. Testing Effectiveness Testing Approach SDLC Stage Additionally, static analysis is notorious for being overly noisy, generating excessive false positives. In large projects, it’s not uncommon to encounter hundreds of thousands of false warnings, making it challenging for developers to prioritize real issues. Code Build Test Deploy Static Analysis White-box Fuzzing Pen Testing Scans code for known issues without actually executing it Scans code in execution with random, most effective inputs Manually simulated Operate attack from outside by authorized tester False Positives Discovered Vulnerabilities - Low complexity Discovered Vulnerabilities - High complexity Penetration testing, on the other hand, is typically performed later in the development stages. As a manual security technique, it is costly and difficult to scale. While it can uncover high-severity issues, these vulnerabilities are often hard to fix since they are discovered late in the process and lack detailed reproduction information essential for debugging. This is why companies turn to approaches like white-box fuzz testing to fill the gap and uncover more bugs earlier in the development process. — 05 What is Fuzz Testing Fuzz testing is one of the most effective ways to find runtime bugs and security issues in C/C++ software. But let’s start with the basics. What is it? Fuzz Testing (aka fuzzing) is a dynamic testing method for finding functional bugs and security issues in software. During a fuzz test, a program or a function under test is executed with thousands of invalid, unexpected, or random inputs in order to crash the application, like a stress test for your application code. Instrumentation Smartly-mutated Inputs White-box fuzzing Fuzzer MyAPI (data) Fuzz Test (Harness) System under Test Feedback (coverage, comparisons, ...) & Bugs When fuzzing is employed in a white-box manner (meaning it has access to your source code so that it can instrument it), the fuzzer gets detailed feedback on the code coverage and the states reached by the automatically generated inputs. To employ white-box fuzzing, you need to write fuzz tests or fuzz harnesses. These are custom-built test wrappers that integrate with the fuzzer to define how inputs should be fed into specific parts of the code—functions or APIs like MyAPI(data). The fuzzing engine actively uses this feedback to guide its mutations, creating new test cases that maximize code coverage and trigger new behaviors. This significantly increases the likelihood of finding bugs and exposing hidden vulnerabilities. You can learn more about fuzzing here. — 06 How Fuzzing Helps With C/C++ Security By feeding software with unexpected or invalid inputs, modern fuzzing tools can uncover dangerous edge cases and behaviors related to communication with memory, such as memory corruption bugs. These include buffer overflows, memory leaks, and other issues relevant to memory-unsafe languages such as C/C++. A few real-world results of using white-box fuzzing : Engineers at Google have already found more than 25,000 bugs in Chrome. 75% of these vulnerabilities were memory issues, such as heap buffer overflows and use-after-free. Microsoft found more than 1,800 bugs in their Office products. Automotive supplier Continental found 57% of bugs through fuzzing. What Industries Are Adopting Fuzzing? Fuzz Testing has proven to be effective in testing critical software where security is a must. Industries such as automotive, medical devices, defense and aerospace, and industrial automation and control systems have adopted fuzzing to eliminate critical bugs in their C/C++ code. In these industries, fuzzing is considered a state-of-the-art technology, and many standards advocate for its use. — 07 Standards advocating for fuzz testing Automotive Medical Devices Industrial Automation and Control Systems Aviation ISO/SAE 21434 Road Vehicles — Cybersecurity Engineering Cybersecurity in Medical Devices: Quality System Considerations and Content of Premarket Submissions by the U.S. Food and Drug Administration (FDA) ISA/IEC 62443-4-1Security for industrial automation and control systems – Part 4-1: Secure product development lifecycle requirements ED-203A / DO-356A Automotive SPICE for Cybersecurity Guidelines Airworthiness Security Methods and Considerations AAMI TIR 57:2016 Principles For Medical Device Security - Risk Management Guidance on cybersecurity for medical devices (MDCG 2019-16) by the European Commission and the Medical Device Coordination Group IEC 81001-5-1 Health software and health IT systems safety, effectiveness and security. Part 5-1: Security — Activities in the product life cycle. Good Use Cases for Fuzz Testing In general, any library or application that handles untrusted or complicated data is well suited for fuzz testing. For example Media Codec Network Protocols, RPC Librarie Crypt Compressio Compilers and Interpreter Regular Expression Matcher Text/UTF processin Database Browser Text Editors/Processor Embedded Syste OS Kernel, Drivers, Supervisors and VMs — 08 What Bugs You Can Find With Fuzzing in C/C++ With fuzzing, you can find all sorts of C/C++ vulnerabilities that can cause your application to crash. For example: Resource Usage Bugs Memory Exhaustio Hangs or Infinite Loop Infinite Recursion Denial of Services (DoS) Logical Bugs Discrepancies between two implementations of the same protoco Round-trip consistency bugs (e.g. compress the input decompress back, compare with the original) — 09 Plain Crashes NULL deferenc Uncaught Exception Segmentation Fault Failed Assertions Memory Issues Buffer Overflow Use After Fre Out of Bound Memory Leak Uninitialized reads How to Trigger Memory Corruptions With Fuzzing? Sanitizers and white-box fuzzing work together to maximize bug detection. White-box fuzzing generates and mutates test inputs to explore deep execution paths, while sanitizers (e.g., ASan, UBSan) detect memory corruption and undefined behavior during execution. Fuzzing increases code coverage, helping sanitizers catch more bugs, while sanitizers provide real-time feedback, allowing the fuzzer to refine inputs and uncover even more vulnerabilities. Together, they create a powerful, automated security testing approach. With fuzzing, you can also find out-of-bounds errors, all kinds of buffer overflows, and other memory allocation errors, but you may have to use specific settings for the used compiler to add the needed instrumentation. As an example, if a fuzzer generates inputs that cause your code to access memory beyond the allocated buffer, these inputs do not necessarily cause the application to crash. With the sanitizers, you get a crash report containing the exact input that caused the issue and corresponding stack trace so that you can easily debug the problem to understand the root cause. So, the sanitizers provide a reliable mechanism to trigger bugs such as memory corruptions during a fuzz test. What is a Sanitizer? Sanitizers are runtime bug detectors that monitor the code and report any issues that are triggered during runtime. The idea behind sanitizers is to trigger crashes when normal application behavior would not do that. — 10 List of Sanitizers for Fuzzing Here is a list of four common C/C++ sanitizers and the vulnerabilities you can find with them if you apply those sanitizers in combination with fuzzing: AddressSanitizer (ASan) is a memory error detector for C/C++. It finds Use after free (dangling pointer dereference Heap buffer overflo Stack buffer overflo Global buffer overflo Use after retur Use after scop Initialization order bug Memory leak UndefinedBehaviorSanitizer (UBSan) is a fast undefined behavior detector implemented in Clang and Compiler-rt ThreadSanitizer (TSan) is a data race detector for C/C++. It finds Signed integer overflo Out of Bounds Arra Out of Bounds BitShift Floating Point Conversion Overflo Dereferencing Misaligned or Null Pointer Data Race MemorySanitizer (MSan) is a detector of uninitialized memory reads in C/C++ programs. — 11 Good Fuzz Testing Tools If you are new to fuzzing, we recommend starting with an AIautomated fuzz testing solutions like CI Fuzz by Code Intelligence. It automates many manual steps for you, so that you just need to launch one command to start fuzzing your code. If you are an advanced user and want to customize a solution for you, you may check out the list of popular open-source fuzzers: AFL++ is a C/C++ fuzzer that employs genetic algorithms to increase the code coverage of the test cases efficiently Honggfuzz is a feedback-driven, easy-to-use fuzzer with interesting analysis options BFuzz is an input-based fuzzer tool that takes .html as input Jazzer is a coverage-guided fuzzer for Java and other JVMbased languages Jazzer.js is a coverage-guided fuzzer for JavaScript and the Node.js platform KernelFuzzer is a Kernel Fuzzer, for fuzzing Windows Syzkaller is an unsupervised coverage-guided kernel fuzzer libFuzzer is a library for coverage-guided fuzz testing and is integrated into the clang/LLVM toolchain Radamsa is a general-purpose fuzzer. Compare whitebox and black-box fuzzers with the free guide “Fuzz Testing Solutions Comparison.” — 12 Setting Up Fuzzing for Your Project Integrating white-box fuzz testing into your project is a bit complex, especially finding the right functions to fuzz, but it's a powerful way to improve software quality. Here's a breakdown of the essential steps Choosing a fuzzing engine: Select a fuzzing tool that fits your project's language and build system. There are many good options available, and starting with a popular one is often a good strategy Preparing Your Code: You'll the chosen compatible with adjustments to how your that the used necessary need to make fuzzer. project This builds. compiler your project might involve For example, supports the it is needed instrumentation used by the fuzzer Finding Candidates/Targets: To unleash the full potential of fuzzing, it is important to select the right entry points into your code base. Which functions cover the most functionality actual fuzz test calls containing the most complexity Creating Fuzz Tests: selected function in Write the the correct context, that including the the needed setup and cleanup. This includes the needed test setup as well as transforming the fuzzer input into usable data structure Configuring the Fuzzer: Set up the fuzzer with your test program and any specific settings needed. This tells the fuzzer what to test and how to run Running the Fuzzer: Let the fuzzer run for a while, ideally as part of your continuous integration (CI) system. It will try many different inputs to find potential issues Analyzing Results: When the fuzzer finds something interesting (like a crash), investigate the issue. The fuzzer usually provides helpful information to track down the problem Integrating into Your Workflow: For the best results, make fuzzing a regular part of your development process. This ensures that new code is tested and potential issues are found early. — 13 While setting up fuzzing involves several steps, it's a worthwhile investment. Especially now, when technologies can automate some of these steps. Intelligence, For runs example, steps 3-6 Spark, an AI autonomously, Test so Agent you by just Code need to launch one command to analyze your code and generate and run fuzz tests. 02 Select fuzz targets 01 AI Test Agent 04 — 14 Create tests 03 Run tests Assess findings & Coverage Introducing Spark: The Next Generation of Fuzzing Assistance By combining static analysis with the latest advances in AI by using large language models (LLMs), Spark can identify bugs and vulnerabilities in unknown code without human interaction. Spark is the first AI agent to find a real-world vulnerability by automatically generating and running a test for a widely used open-source software (wolfSSL). Watch the recording of the live demo of fuzzing the wolfSSL’s library here. With Spark, white-box fuzzing is now as simple as: Setting up a testing goal (how much code coverage you want to achieve) Launching Spark Reviewing discovered vulnerabilities. For example, you can set a target of 75% coverage and launch the spark command. Then, Spark would automatically generate fuzz tests and stop fuzzing once it reaches the goal. This is how it would look like in your terminal: — 15 When you launch Spark, it operates as follows under the hood: 1. Analyzes your codebase and identifies the most important functions and APIs to fuzz. Each fuzzing entry point is scored based on its expected impact using four key metrics. Andreas Lackner, Senior Software Development Engineer, Vector Informatik By reducing the manual effort for creating and integrating fuzz tests, we are able to bring our cycle time down and further improve the quality of our embedded software. 2. Generates fuzz tests (harnesses) for each function. It extracts the correct context needed to test the target function and leverages large language models (LLMs) to create the fuzz test by employing advanced prompting techniques. To ensure high-quality working fuzz tests, Spark explores multiple alternative fuzz tests, validates and refines the created fuzz tests. 3. Runs the generated tests to maximize code coverage and trigger bugs. 4. Flags findings, providing details such as the exact lines of code where issues occur, stack traces, and triggering inputs to assist in root cause analysis. How to Start Using AI-Automated Fuzzing If you’re looking to secure C/C++ with minimal manual effort, book a free call with our experts for a tailored demo of CI Fuzz and its AI Test Agent. To start using AI Test Agent, you’ll need to Install CI Fuzz Ensure access to LLMs. During the call, Code Intelligence’s experts will guide you through the setup process, share industry best practices, and provide insights on pricing options. Start finding bugs autonomously — 16 Schedule a free 30-minute product demo with Code Intelligence's experts to learn how fuzzing can strengthen your testing strategy. Book a demo Trusted by: Code Intelligence GmbH, Rheinwerkallee 6, 53227 Bonn. Follow us on LinkedIn, X and Youtube
0
You can add this document to your study collection(s)
Sign in Available only to authorized usersYou can add this document to your saved list
Sign in Available only to authorized users(For complaints, use another form )