count_digits incorrectly returns zero for zero. The correct result is one. A name of 251 characters with a salary of zero will require 257 characters (251 for name, 1 for salary, 5 for color, space, dollar sign, new-line, and null), but len will be incorrectly computed as 256, and len > sizeof(buffer) will not be triggered, so the code will overflow buffer.

(Another problem is strlen has undefined behavior when name is not null-terminated, but the context of name is not clear from the problem statement.)

Answer from Eric Postpischil on Stack Overflow
🌐
Cern
security.web.cern.ch › recommendations › en › codetools › c.shtml
C Programming Vulnerabilities - Computer Security - CERN
Most vulnerabilities in C are related to buffer overflows and string manipulation. In most cases, this would result in a segmentation fault, but specially crafted malicious input values, adapted to the architecture and environment could yield to arbitrary code execution.
Discussions

c - How can I find vulnerabilities in this code? - Stack Overflow
In this code there are 4 vulnerable points. Does anyone know how to find them? char *alloc_and_copy(char *dst,char src[], unsigned int nbcells) { unsigned char size; size = nbc... More on stackoverflow.com
🌐 stackoverflow.com
Dynamic tools to detect vulnerabilities in software applications written in c? - Information Security Stack Exchange
I am doing a project on detecting ... of which some have source code available and some do not. Please suggest some technique that can help me detect vulnerabilities either at compile time or run-time. Is there any new way that can be used in finding out the buffer overflow ... More on security.stackexchange.com
🌐 security.stackexchange.com
February 21, 2013
vulnerability - Some vulnerable projects in C or C++ for a lecture? - Information Security Stack Exchange
Closed 6 years ago. ... I'm looking for some real projects which have stack overflow vulnerabilities. The important thing is, I am going to teach finding the vulnerabilities and the way of fixing them by these examples. So, the vulnerabilities should be simple to find and simple to patch. Do you know any source code ... More on security.stackexchange.com
🌐 security.stackexchange.com
May 24, 2017
Vulnerability Scanning Tools in C/C++
Honestly. If the checker Says you have vulnerable code somewhere. Check it. Humans eyes on it to verify. More on reddit.com
🌐 r/cpp
11
5
July 10, 2022
People also ask

When will I have access to the lectures and assignments?
To access the course materials, assignments and to earn a Certificate, you will need to purchase the Certificate experience when you enroll in a course. You can try a Free Trial instead, or apply for Financial Aid. The course may offer 'Full Course, No Certificate' instead. This option lets you see all course materials, submit required assessments, and get a final grade. This also means that you will not be able to purchase a Certificate experience.
🌐
coursera.org
coursera.org › browse › computer science › computer security and networks
Identifying Security Vulnerabilities in C/C++Programming | Coursera
What will I get if I subscribe to this Specialization?
When you enroll in the course, you get access to all of the courses in the Specialization, and you earn a certificate when you complete the work. Your electronic Certificate will be added to your Accomplishments page - from there, you can print your Certificate or add it to your LinkedIn profile.
🌐
coursera.org
coursera.org › browse › computer science › computer security and networks
Identifying Security Vulnerabilities in C/C++Programming | Coursera
Is financial aid available?
Yes. In select learning programs, you can apply for financial aid or a scholarship if you can’t afford the enrollment fee. If fin aid or scholarship is available for your learning program selection, you’ll find a link to apply on the description page.
🌐
coursera.org
coursera.org › browse › computer science › computer security and networks
Identifying Security Vulnerabilities in C/C++Programming | Coursera
Top answer
1 of 1
1

How can I find vulnerabilities in this code?

With experience, a good set of compiler options, a static source code analyzer, a dynamic analyzer, ... anything you know how to use. If you don't know how to use such, I'm afraid that you have to learn.

You can find the worst problems by raising the warning level of your compiler to the max and even give option like -pedantic for GCC. The same applies to the analyzers of which the static kind is quite simple to use.

Then you can build tables of possible control and data flows. For instance scanf() can do anything of these:

  1. Read nothing at all into t1 leaving it completely uninitialized, perhaps because of I/O errors.
  2. Read a zero length string; just one character, '\0', will be stored in t1.
  3. Read anything between the previous and the next length.
  4. Read a string filling t1 up to the last character, but not overflowing it.
  5. Read a string longer than t1 provides space for.
  6. Read a string very much longer than t1 provides space for.

Some of these might have the same effect, beware. Then think about what will happen further down the control flow.

Do this for every function call, every assignment, and every instruction. Some instructions are simple and don't do any harm, others are quite tricky. You have to read the documentation of the functions carefully, and the C standard, may be more than one version of it.

There are some traps to distract you from the real errors, too.

Does anyone know how to find them?

Yes, a lot of people know this.

Well, you didn't ask for the vulnerabilities. And from your comment you didn't want to, perfect. ;-)

🌐
PVS-Studio
pvs-studio.com › en › blog › posts › a0028
Detection of vulnerabilities in programs with the help of code analyzers
August 10, 2008 - MOPS (MOdel checking Programs for Security) is a tool to search security vulnerabilities in C programs. It is intended for dynamic patch to make a C program correspond to a static model.
🌐
YouTube
youtube.com › watch
Security: Workshop 2 - Finding security vulnerabilities in C/C++ with CodeQL - YouTube
CodeQL is GitHub's expressive language and engine for code analysis, which allows you to explore source code to find bugs and security vulnerabilities. Durin...
Published   December 18, 2020
🌐
Tech-FAQ -
tech-faq.com › home
How to Find Security Vulnerabilities in Source Code - Tech-FAQ
April 6, 2019 - The original, and still the best, method for finding security vulnerabilities in source code is to read and understand the source code. Source code security vulnerabilities will vary between languages and platforms. Items to look for in C code include: Potential vulnerability Function calls ...
Find elsewhere
🌐
GitHub
github.com › david-a-wheeler › flawfinder
GitHub - david-a-wheeler/flawfinder: a static analysis tool for finding vulnerabilities in C/C++ source code · GitHub
Flawfinder is a simple program that scans C/C++ source code and reports potential security flaws. It can be a useful tool for examining software for vulnerabilities, and it can also serve as a simple introduction to static source code analysis ...
Starred by 566 users
Forked by 85 users
Languages   Python 53.7% | Roff 28.8% | HTML 7.8% | Makefile 5.2% | C 3.9% | Lex 0.2%
🌐
Coursera
coursera.org › browse › computer science › computer security and networks
Identifying Security Vulnerabilities in C/C++Programming | Coursera
February 23, 2021 - This course builds upon the skills and coding practices learned in both Principles of Secure Coding and Identifying Security Vulnerabilities, courses one and two, in this specialization. This course uses the focusing technique that asks you to think about: “what to watch out for” and “where to look” to evaluate and ultimately remediate fragile C++ library code.
Rating: 4.6 ​ - ​ 81 votes
🌐
GitHub
github.com › hardik05 › Damn_Vulnerable_C_Program
GitHub - hardik05/Damn_Vulnerable_C_Program: An example C program which contains vulnerable code for common types of vulnerabilities. It can be used to show fuzzing concepts. · GitHub
Makefile is included with it. ... AFL will automatically generate new test cases and discover most of the vulnerabilities mentioned above. thats the beauty of AFL :) ... You need to modify the C code, you can get the updated code from here: https://github.com/hardik05/Damn_Vulnerable_C_Program/blob/master/dvcp_libfuzzer.c
Starred by 721 users
Forked by 184 users
Languages   Rust 70.7% | Makefile 25.2% | LLVM 3.1% | C 1.0% | C++ 0.0% | M4 0.0%
🌐
Snyk
snyk.io › blog › unintimidating-intro-to-c-cpp-vulnerabilities
An unintimidating introduction to the dark arts of C/C++ vulnerabilities | Snyk
April 15, 2022 - The following loop causes a heap buffer overflow as we write to a non-allocated memory location, which may, in turn, be used by an attacker to execute arbitrary code. Dereferencing is when we perform an action on a value at an address. To better explain this vulnerability, let’s look at an example:
🌐
Medium
int0x33.medium.com › day-49-common-c-code-vulnerabilities-and-mitigations-7eded437ca4a
Day 49: Common C Code Vulnerabilities and Mitigations | by int0x33 | Medium
February 17, 2019 - A lot of C vulnerabilities relate to buffer overflows. Buffers areas of memory set aside to hold data, when vulnerable code is written allows an exploit to write over other important values in memory, like the instructions that the CPU must ...
Top answer
1 of 4
2
  • Avalanche is a dynamic defect detection tool that generates "inputs of death" - input data reproducing critical bugs and vulnerabilities in the analysed program.

  • BoundsChecker is a memory checking and API call validation tool used for C++ software development with Microsoft Visual C++.

  • Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail.

  • !exploitable (pronounced “bang exploitable”) is a Windows debugging extension (Windbg) that provides automated crash analysis and security risk assessment. The tool first creates hashes to determine the uniqueness of a crash and then assigns an exploitability rating to the crash: Exploitable, Probably Exploitable, Probably Not Exploitable, or Unknown.

2 of 4
2

I usually use fuzzing in order to identify vulnerabilities in software with or without the source code. The fuzzing technique consists on manipulating the inputs to an application in a semi-automated way to produce errors that you have to study later using a debugger or inspecting the source code.

For example, you can program a fuzzer for the PDF format and use it to generate malformed PDF files and open them with your software that is supposed to fail gracely when reading malformed PDFs.

With a fuzzer you can test thousands of different combinations of inputs covering lots of cases but it is method that does not guarantee that there are no bugs.

You can use the Peach Fuzzing Platform that is a good framework to implement fuzzers and includes the tools to open the debugger automaticaly and logging the inputs when a bug is found.

🌐
Springer
link.springer.com › home › tests and proofs › conference paper
Detection of Security Vulnerabilities in C Code Using Runtime Verification: An Experience Report | Springer Nature Link
Despite significant progress made by runtime verification tools in recent years, memory errors remain one of the primary threats to software security. The present work is aimed at providing an objective up-to-date experience study on the capacity of modern online runtime verification tools to automatically detect security flaws in C programs.
🌐
Quora
quora.com › What-are-common-security-vulnerabilities-that-come-from-writing-C-code
What are common security vulnerabilities that come from writing C code? - Quora
The most common, I think, is a “buffer overflow”. The most common is if you have a string buffer that is 1000 bytes long, and you write a 1000 byte ASCII string into the buffer, then you have overflowed it.
🌐
Code Intelligence
code-intelligence.com › blog › most-dangerous-vulnerabilities-cwes-in-c-2025
Top Six Most Dangerous Vulnerabilities in C and C++
Detecting Weaknesses – Flags potential vulnerabilities along with the specific line of code where the issue occurs, the stack trace, and the triggering input, enabling developers to fix the issue quickly. Setting up a white-box fuzz testing tool to find the first vulnerabilities can require ...
🌐
We Live Security
welivesecurity.com › 2017 › 01 › 30 › examples-vulnerable-code-find
Some examples of vulnerable code and how to find them
January 30, 2017 - One of the simplest scenarios in ... immediately - goes hand in hand with the copying of buffer data using functions such as strcpy, without performing any check on the size of the copy....