Multiple choice technology security

Is there a vulnerability in this code? If yes, which line(s) int main (int argc, char argv[]){ char chararray[3]; int intarray[3]; int i; strncpy(chararray, argv[1], sizeof(chararray) - 1); for (i=0;i<=3;i++){ /*1/ chararray[i]= getchar(); intarray[i]=i*i; /2/ } }

  1. for (i=0;i<=3;i++)

  2. intarray[i]=i*i;

  3. Both

  4. None

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

The loop runs for i=0,1,2,3 but arrays are size 3 (indices 0-2). When i=3, both chararray[3] and intarray[3] write past array bounds, buffer overflow. The loop condition i<=3 should be i<3 or i<=2. Line 1 is the vulnerability source.