Multiple choice technology security

What is the vulnerability ? int main (int argc, char *argv[]){ char k[3]; int i=0,j=1; char buffer[50]; strncpy(buffer, argv[1], sizeof(buffer) - 1); buffer[49]='/0'; unsigned char ch='a'; k[0]=1; do{ i++; k[i]=ch+i; } while(i<3); return 0; }

  1. Heap overflow

  2. Integer overflow

  3. Off by one error

  4. None

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

The loop 'do { i++; k[i]=ch+i; } while(i<3);' will execute for i=1, 2, and 3. Since 'k' is defined as 'char k[3]', the valid indices are 0, 1, and 2. Writing to 'k[3]' causes an off-by-one error (buffer overflow).