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.
- Find the type of triangle from the given sides
- tgamma() method in C/C++ with Examples
- Modulo Operator (%) in C/C++ with Examples
- fpclassify() method in C/C++ with Examples
- Count number of pairs with positive sum in an array
- Must Do Coding Questions Company-wise
- getch() function in C with Examples
- Chain of Pointers in C with Examples
- Pointer Expressions in C with Examples
- Speed up Code executions with help of Pragma in C/C++
- Dockerizing a simple Django app
- Count the number of words with given prefix using Trie
- Introduction to the C99 Programming Language : Part I
- Jagged Array or Array of Arrays in C with Examples