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.
- Data Visualization Using Chartjs and Django
- Rabin Cryptosystem with Implementation
- Difference between Increment and Decrement Operators
- Introduction to Project Lombok in Java and How to get started?
- Simplified International Data Encryption Algorithm (IDEA)
- Problem in comparing Floating point numbers and how to compare them correctly?
- exit(0) vs exit(1) in C/C++ with Examples
- Predefined Macros in C with Examples
- How to create GUI in C programming using GTK Toolkit
- Game Theory (Normal-form Game) | Set 6 (Graphical Method [2 X N] Game)
- Game Theory (Normal-form Game) | Set 7 (Graphical Method [M X 2] Game)
- SFML Graphics Library | Quick Tutorial
- ctype.h(<cctype>) library in C/C++ with Examples
- Game Theory (Normal-form Game) | Set 4 (Dominance Property-Pure Strategy)