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.
- Dividing a Large file into Separate Modules in C/C++, Java and Python
- C program to store Student records as Structures and Sort them by Name
- Android | App to Add Two Numbers
- Similarities and Differences between Ruby and C language
- Count of strings that become equal to one of the two strings after one removal
- Program to copy the contents of one array into another in the reverse order
- Interesting facts about C Language
- Machine Learning | Outlier
- Program to Reverse a String using Pointers
- Difference between Structure and Array in C
- Structured Programming Approach with Advantages and Disadvantages
- Commonly used String functions in C/C++ with Examples
- JSTL | JSP Standard Tag Library
- Program to check if two strings are same or not