Skip to main content
C Bug Hunt Hard +35 XP

Buffer Overflow

This code has a dangerous security vulnerability.

CFind the bug
1char buf[10];
2gets(buf);
The bug is on line 2

Select the correct fix

Show answer and explanation

Answer: Use fgets(buf, sizeof(buf), stdin) instead

gets() doesn't check buffer length — classic buffer overflow. fgets() with a size limit is always safer.

Hint: gets() is unsafe — it's even removed in C11.

What this challenge tests

Bug Hunt in C: security, buffer-overflow, strings.

Related challenges