Multiple choice technology security

What can go wrong in following code? #include int main(int argc, char *argv[]){ if(argc != 3){ printf("usage: %s [source] [dest]\n", argv[0]); exit(1); } char buffer1[5]; strcpy(buffer1, argv[1]); char buffer2[5]; strcpy(buffer1, argv[1]); char x; FILE *file[2]; file[0] = fopen(buffer1,"r+"); file[1] = fopen(buffer2,"w+"); for(x = 0; x < 2; x++){ if(file[x] == NULL){ printf("error opening file.\n"); exit(1); } } do { x = fgetc(file[0]); fputc(x,file[1]); } while(x != EOF); for(x = 0; x < 2; x++) fclose(file[x]); return 0; }

  1. XSS

  2. Arc Injection

  3. Buffer Overflow

  4. Arc Injection AND Buffer Overflow

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The code has multiple vulnerabilities: (1) Buffer overflow - strcpy() without bounds checking on buffer1 and buffer2 can overflow the 5-byte buffers. (2) Arc injection - FILE *file[2] creates an array of 2 FILE pointers but the code attempts to use file[x] where x can be manipulated. (3) The second strcpy uses buffer1 instead of buffer2 - this is a bug that copies argv[1] into buffer1 twice. Option D correctly identifies both arc injection and buffer overflow.