I have a program in C that is vulnerable to buffer overflow attacks. I need to understand how to make it not vulnerable to these attacks, and why the code added would do so-
#include <stdio.h>
#include <string.h>
int main (int argn, char** argv) {
char buffer[100];
int i;
long *addr_ptr; //a long is guaranteed to be a four-byte word
strcp(buffer,argv[1]); //copies chars of argv[1] without bound
addr_ptr = (long *) buffer;
for (i = 0; i < 35; i++) {
printf(“%02i:%08x:%08x\n”, //%08x displays hex chars
i,(unsigned int) addr_ptr, (unsigned int) *addr_ptr);
addr_ptr++;