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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Shortest path in a complement graph
- Difference between C and Dart
- Count number of Unique Triangles using Operator overloading
- Difference between Sentinel and Counter Controlled Loop in C
- Why do we need reference variables if we have pointers
- What are the differences between C and Embedded C?
- Sorting algorithm visualization : Insertion Sort
- Fast Doubling method to find the Nth Fibonacci number
- Macros and its types in C/C++
- Count number of ways to convert string S to T by performing K cyclic shifts
- Find the next greater element in a Circular Array
- Unique subsequences of length K with given sum
- Kth smallest or largest element in unsorted Array | Set 4
- Total number of cells covered in a matrix after D days