# Buffer Overflow

**Example 1: C**

**Vulnerable Code:**

```c
cCopy codechar buffer[10];
strcpy(buffer, "This string is too long");
```

**Reason for vulnerability:** Copying a string that exceeds the buffer size, leading to buffer overflow.

**Fixed Code:**

```c
cCopy codechar buffer[10];
strncpy(buffer, "This string", sizeof(buffer) - 1);
buffer[sizeof(buffer) - 1] = '\0';
```

**Reason for fix:** Use `strncpy` and ensure the buffer is null-terminated.
