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.
- ML | Training Image Classifier using Tensorflow Object Detection API
- __builtin_inf() functions of GCC compiler
- TensorFlow 2.0
- Count substrings that contain all vowels | SET 2
- How can we use Comma operator in place of curly braces?
- Basic Code Optimizations in C
- Interesting Facts in C Programming | Set 2
- Constants vs Variables in C language
- Sum of an array using MPI
- What is the Role of Java in the IT Industry?
- Program for Gauss Siedel Method (Computational Mathematics)
- AI Model For Neurodegenerative Diseases
- Difference between pointer to an array and array of pointers
- dot (.) operator in C/C++