Consider the below program.
The code looks simple, it reads string from standard input and prints the entered string, but it suffers from Buffer Overflow as gets() doesn’t do any array bound testing. gets() keeps on reading until it sees a newline character.
To avoid Buffer Overflow, fgets() should be used instead of gets() as fgets() makes sure that not more than MAX_LIMIT characters are read.
Please write comments if you find anything incorrect in the above article, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- GeeksforGeeks Skill-Dependence Days 2020 - A Battle Against Unemployment
- Swap the first and last character of a string in Java
- What happens when we call a Function
- Remove the first and last occurrence of a given Character from a String
- How does Volatile qualifier of C works in Computing System
- Header files in C/C++ with Examples
- C Programming For Beginners - A 20 Day Curriculum!
- Tips for testing code in Compeititive programming
- Important functions of STL Components in C++
- Tr0ll 3 Walkthrough of Check the Flag or CTF Problem
- What are the C programming concepts used as Data Structures
- Array of Structures vs. Array within a Structure in C/C++
- Difference between Identifiers and Variables in C
- Difference between C and Objective C