Here is the List of Some unsafe C Functions with their replaced New Function

  • strcpy -> strncpy -> strlcpy/strcpy_s
  • strcat -> strncat -> strlcat/strcat_s -strtok
  • sprintf -> snprintf
  • vsprintf -> vsnprintf
  • gets -> fgets/gets_s
  • makepath -> _makepath_s (MSDN)
  • _splitpath -> _splitpath_s (MSDN)
  • scanf/sscanf -> sscanf_s (MSDN)
  • snscanf -> _snscanf_s (MSDN)
  • strlen -> strnlen_s (MSDN)

Certain functions behave in dangerous ways regardless of how they are used. Functions in this category were often implemented without taking security concerns into account. The gets() function is unsafe because it does not perform bounds checking on the size of its input.

An attacker can easily send arbitrarily-sized input to gets() and overflow the destination buffer. Similarly, the >> operator is unsafe to use when reading into a statically-allocated character array because it does not perform bounds checking on the size of its input. An attacker can easily send arbitrarily-sized input to the >> operator and overflow the destination buffer.

The code below calls gets() to read information into a buffer.

char buf[24];
printf("Please enter your name and press <Enter>\n");
gets(buf);
...
}

However, the programmer uses the function gets() which is inherently unsafe because it blindly copies all input from STDIN to the buffer without checking size. This allows the user to provide a string that is larger than the buffer size, resulting in an overflow condition

You can read More about Dangers in C/C++ further here..

  1. http://www.dwheeler.com/secure-class/Secure-Programs-HOWTO/dangers-c.html
  2. http://www.dwheeler.com/secure-programs/
  3. http://courses.cs.washington.edu/courses/cse341/04wi/lectures/26-unsafe-languages.html
Answer from Blackhat002 on Stack Overflow
Top answer
1 of 5
9

Here is the List of Some unsafe C Functions with their replaced New Function

  • strcpy -> strncpy -> strlcpy/strcpy_s
  • strcat -> strncat -> strlcat/strcat_s -strtok
  • sprintf -> snprintf
  • vsprintf -> vsnprintf
  • gets -> fgets/gets_s
  • makepath -> _makepath_s (MSDN)
  • _splitpath -> _splitpath_s (MSDN)
  • scanf/sscanf -> sscanf_s (MSDN)
  • snscanf -> _snscanf_s (MSDN)
  • strlen -> strnlen_s (MSDN)

Certain functions behave in dangerous ways regardless of how they are used. Functions in this category were often implemented without taking security concerns into account. The gets() function is unsafe because it does not perform bounds checking on the size of its input.

An attacker can easily send arbitrarily-sized input to gets() and overflow the destination buffer. Similarly, the >> operator is unsafe to use when reading into a statically-allocated character array because it does not perform bounds checking on the size of its input. An attacker can easily send arbitrarily-sized input to the >> operator and overflow the destination buffer.

The code below calls gets() to read information into a buffer.

char buf[24];
printf("Please enter your name and press <Enter>\n");
gets(buf);
...
}

However, the programmer uses the function gets() which is inherently unsafe because it blindly copies all input from STDIN to the buffer without checking size. This allows the user to provide a string that is larger than the buffer size, resulting in an overflow condition

You can read More about Dangers in C/C++ further here..

  1. http://www.dwheeler.com/secure-class/Secure-Programs-HOWTO/dangers-c.html
  2. http://www.dwheeler.com/secure-programs/
  3. http://courses.cs.washington.edu/courses/cse341/04wi/lectures/26-unsafe-languages.html
2 of 5
7

strncpy is not a safe replacement for strcpy. In fact, these functions are unrelated, despite the unfortunate similarity in the naming. Safe replacement for strcpy is a non-standard function strlcpy provided by some *nix implementations as an extension. Usage of strncpy for "safe" string copying is an immediate sign of incompetent code.

Another group of unsafe functions (albeit unsafe for a different reason) are functions from ato.. group: atoi, atof, atol and so on. These functions trigger undefined behavior in case of overflow. Their safe replacements are functions from strto... group: strtol, strtod and such.

There's nothing "unsafe" about your copy_buf function in a sense that it provides the calling code with all means necessary to perform a safe call to copy_buf. The responsibility to pass the correct values in this case is placed on the caller.

Your read_chunk function is much more dangerous, since the calling code has no way of knowing how big the buffer is supposed to be. There's no perfect solution for this function that would work well with a buffer passed from outside. It makes sense to at least make the calling code to pass the size of the buffer as well. This will allow read_chunk to make sure the buffer is not overflowed. Also, read_chunk should inform the calling code about incomplete reads. You should provide the caller with means to complete the read.

🌐
Cern
security.web.cern.ch › recommendations › en › codetools › c.shtml
C Programming Vulnerabilities - Computer Security - CERN
The strcpy built-in function does not check buffer lengths and may very well overwrite memory zone contiguous to the intended destination. In fact, the whole family of functions is similarly vulnerable: strcpy, strcat and strcmp.
Discussions

In your opinions, what is wrong with the C language? What did they do poorly, etc?
The problem with C is when people want to compare it with higher-level languages. This simply has no point. If you find yourself thinking "crap, C has no GC!", "C hasn't a full blown type system!" or something like that, then you're not using the right tool for your task. More on reddit.com
🌐 r/programming
687
54
July 19, 2009
Buffer Overflow Vulnerability C Code
I'm assuming this is a copy paste of your homework, so, did you try to do it and have an specific question? Are your stuck somewhere? More on reddit.com
🌐 r/C_Programming
6
0
February 28, 2023
🌐
Code Intelligence
code-intelligence.com › blog › most-dangerous-vulnerabilities-cwes-in-c-2025
Top Six Most Dangerous Vulnerabilities in C and C++
Fuzz testing (or fuzzing) is an automated testing technique that feeds randomly generated, unexpected, or malformed inputs into a program to detect crashes and vulnerabilities. Fuzzing helps uncover security flaws that traditional testing methods might miss, making it a crucial approach for securing C and C++ applications. Identifying Targets – Fuzzing tools need to determine which critical functions or APIs execute a substantial amount of code and should be tested.
🌐
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
An example C program which contains vulnerable code for common types of vulnerabilities. It can be used to show fuzzing concepts. - hardik05/Damn_Vulnerable_C_Program
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%
🌐
Medium
medium.com › @capturethebugs › common-c-vulnerabilities-56ffad22581e
Common C Vulnerabilities. Introduction | by Capture The Bug | Medium
September 18, 2022 - Mitigation: To mitigate buffer overflows due to strcmp(), you can either use the strncmp() function or first calculate the length of the values before comparing the strings. The C language uses format specifiers to accept and print input from the user. For example, to print an integer date type value, you can make use of the %d format specifier, %s for string, etc. ... Format string vulnerability occurs when the program expects a value, but instead the user enters a format specifier.
🌐
GeeksforGeeks
geeksforgeeks.org › c language › security-issues-in-c-language
Security issues in C language - GeeksforGeeks
August 6, 2025 - Vulnerable Library Functions: CWE ... input-output library of the C language. It does not have any check for buffer size and malicious input can easily cause a buffer overflow....
🌐
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 - Uncontrolled format string is a vulnerability category which can cause information leakage and overwriting of memory. The following functions are also vulnerable: printf, fprintf, sprintf and snprintf.
Find elsewhere
🌐
James Madison University
w3.cs.jmu.edu › lam2mo › cs261 › c_funcs.html
CS 261 - C Functions
Pay particular attention to the list near the bottom of unsafe functions -- you are forbidden from using these on CS 261 projects. ... int snprintf (char *buffer, size_t bufsize, char *format, ...) Copy a string or convert data to string
🌐
Medium
infosecwriteups.com › common-c-vulnerabilities-b84777e071b9
Common C Vulnerabilities. Introduction | by Security Lit Limited | InfoSec Write-ups
May 10, 2022 - The problem arises because gets() doesn’t perform bound checking, which means a user can make the program accept a string with an infinite size. This can cause a buffer overflow attack by overwriting the memory area and also lead to code execution. ... A collection of write-ups from the best hackers in the world on topics ranging from bug bounties and CTFs to vulnhub machines, hardware challenges and real life encounters.
🌐
ScienceDirect
sciencedirect.com › topics › computer-science › vulnerable-function
Vulnerable Function - an overview | ScienceDirect Topics
A vulnerable function is a code component in which a security weakness exists that can be exploited by attackers. For example, a buffer overflow flaw allows user input to overwrite local variables and corrupt program state information in the process’s stack memory.
🌐
ResearchGate
researchgate.net › figure › List-of-Vulnerable-Functions-by-Vulnerability-Type_tbl3_325272020
List of Vulnerable Functions by Vulnerability Type. | Download Table
In addition, as shown in Table 3, the vulnerable function list is composed of 50 functions that can cause each of the four types of vulnerability, such as buffer overflow, format string, race condition, and multiple command execution.
🌐
Tenouk
tenouk.com › Bufferoverflowc › Bufferoverflow6.html
The vulnerable and the exploit program examples using C programming language based on the SUID/GUID programs on Linux opensource machine with Intel microprocessor
A step-by-step and how-to tutorial on testing and proving the buffer overflow vulnerabilities and exploits using GNU C programming language on Linux platforms and Intel x86 microprocessor
🌐
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 - Mitigation is simple: the recommendation is to use the fgets function, which also checks the length of the input and not only the existence of the “end sequence character.” · Use after free vulnerabilities are appropriately self-described: they occur when you use a variable reference after ...
🌐
ResearchGate
researchgate.net › figure › The-example-of-C-functions-a-A-vulnerable-function-b-Tthe-revised-function_fig3_357931855
The example of C functions. (a) A vulnerable function. (b) Tthe revised... | Download Scientific Diagram
Download scientific diagram | The example of C functions. (a) A vulnerable function. (b) Tthe revised function. from publication: Deep Neural Embedding for Software Vulnerability Discovery: Comparison and Optimization | Due to multitudinous vulnerabilities in sophisticated software programs, the detection performance of existing approaches requires further improvement.
🌐
Wiley Online Library
onlinelibrary.wiley.com › doi › abs › 10.1002 › spy2.8
Detection of security vulnerabilities in C language applications - Boudjema - 2018 - SECURITY AND PRIVACY - Wiley Online Library
December 19, 2017 - Static analysis of the code helps to automate this process, by guiding the programmer toward the potential vulnerabilities before they are discovered by an adversary. We investigate in this paper vulnerabilities that arise in C code through the calling of library functions.
🌐
LiU
ida.liu.se › ~TDDC90 › literature › slides › TDDC90_Vulnerabilities_II.pdf pdf
Vulnerabilities in C/C++ programs – Part II - TDDC90
Detailed lab instructions are found on the lab page. The course literature consists of a set of articles. All articles on the literature page together with the lecture slides (posted on the same page as the schedule) are mandatory reading for the exam. We recommend that you read the articles ...
🌐
SonarSource
rules.sonarsource.com › c › type › vulnerability › rspec-1081
C static code analysis | Vulnerability
Unique rules to find Bugs, Vulnerabilities, Security Hotspots, and Code Smells in your C code
🌐
Tonyng
pentest.tonyng.net › tag › c-functions-vulnerable
C functions vulnerable – Penetration Test Resource Page
Samba Server Exploitation GDB Tutorial Hacking Samba on Ubuntu and Installing the Meterpreter · 445 airodump-ng APSB09-09 authentication bypass Buffer Overflow burp bypassuac cfm shell C functions vulnerable data breach fckeditor getsystem getuid google kali kali wifi hack Linux Privilege Escalation memory corruption memory layout metasploit Meterpreter meterpreter command mitm MS08_067 ms11-080 msfvenom null session oscp oscp exp sharing Privilege Escalation ps psexec pyinstaller pywin32 rpcclient shellcode smb stack steal_token systeminfo UAC bypass union injections wifi hacking wifiphisher wmic
🌐
Snyk
snyk.io › blog › top-5-c-security-risks
Top 5 C++ security risks | Snyk
August 16, 2022 - In addition to using OS and compiler features, we must implement good coding practices, including bounds checking. We should avoid using standard library functions vulnerable to buffer overflow attacks, such as get, strcpy, strcat, scanf, and printf...