Tag: security

Questions Related to security

Which statement creates a buffer over flow? #include #include #include int main (int argc, char *argv[]) { int i=0,j=1; char ipstring[80]; for (;i<=3;i++){ cout<

  1. j=getchar();

  2. gets(ipstring);

  3. Both

  4. None


Correct Option: B
  1. This is a double free vulnerability and must be fixed

  2. The second call to free() will return an error

  3. There might be compiler warnings, but the program will run fine

  4. This is not a security issue


Correct Option: A

While trying to print an eight character long name, which of the following will introduce a security vulnerability ? printf ("%.8s",name); /* 1 / printf (name); / 2 / printf ("%s",name); / 3 / printf ("%8c", name); / 4 */

  1. printf ("%.8s",name); AND printf (name);

  2. printf (name); AND printf ("%s",name);

  3. printf ("%s",name); AND printf ("%8c", name);

  4. printf (name);


Correct Option: B

AI Explanation

To answer this question, we need to understand how the printf function works and how it handles formatting and printing strings.

Option A) printf ("%.8s",name); AND printf (name); The first printf statement uses the format specifier "%.8s" which limits the output to a maximum of 8 characters. This ensures that only the first 8 characters of the name are printed. The second printf statement does not have a format specifier, so it will print the entire string. This combination is safe and does not introduce a security vulnerability.

Option B) printf (name); AND printf ("%s",name); The first printf statement does not have a format specifier, so it will print the entire string. This can be a security vulnerability if the name contains a format string that can be exploited. The second printf statement uses the format specifier "%s" which is safe and will print the entire string. This combination introduces a security vulnerability because the first printf statement does not limit the output.

Option C) printf ("%s",name); AND printf ("%8c", name); Both printf statements in this option use safe format specifiers. The first printf statement ("%s") will print the entire string, and the second printf statement ("%8c") will print the first character of the name followed by 7 spaces. This combination is safe and does not introduce a security vulnerability.

Option D) printf (name); This option does not have a format specifier, so it will print the entire string. This can be a security vulnerability if the name contains a format string that can be exploited.

Based on the explanations above, option B is the correct answer. This combination of printf statements introduces a security vulnerability because the first printf statement does not limit the output.

  1. scanf("%.8s", name);

  2. scanf("%8s", name);

  3. scanf("%8c", name);

  4. scanf("%s", name);


Correct Option: B

What will be sizeof(name) return? char *name="32000";

  1. 4 - it is the size of the pointer

  2. 5 - it is the number of characters in the string that the pointer points to

  3. 4 - it is the size when 32000 is stored as integer

  4. 1 - it is the size of a character variable


Correct Option: A