Tag: security

Questions Related to security

  1. Program works when there is only 1 argument with program

  2. Program works when there are 3 arguments with program

  3. Program works when there are 4 arguments with program

  4. Program never executes successfully


Correct Option: D
  1. A run-time error is encountered and the program aborts

  2. unsigned int variables cannot store the sign (+ or -) of the number. The sign is discarded and only the number is stored in i

  3. A large positive number will be stored in i

  4. Unsigned int variables cannot store signed numbers. Hence in this program i will contain garbage values.


Correct Option: C
  1. 1289945278

  2. garbage. Integer j cannot hold such large values

  3. 9879879870

  4. Program is aborted


Correct Option: A
  1. Shell environment variables

  2. Data received via encrypted network channels

  3. argv[0] can only have either null or program name

  4. no external input must be trusted


Correct Option: D
  1. DNS Spoofing

  2. Command Injection

  3. Path Traversal

  4. Command Injection AND Path Traversal


Correct Option: D

In the following code snippet, how should a pointer be deleted int main (int argc, char argv[]) { char j=new char[100]; j=argv[1]; int k=atoi(j); /delete here/ return 0; }

  1. delete j

  2. free j

  3. it is not supposed to be deleted

  4. delete [] j


Correct Option: D

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) delete j - This option is incorrect because the pointer j was assigned a new value from argv[1] using the assignment operator. Thus, delete j would only delete the memory allocated for the new value of j, not the previously allocated memory.

Option B) free j - This option is incorrect because the free function is used to deallocate memory allocated using the malloc function in C. In this code snippet, the memory was allocated using the new operator in C++, so free should not be used.

Option C) it is not supposed to be deleted - This option is incorrect. Memory allocated dynamically using the new operator should be deallocated using the delete operator to prevent memory leaks.

Option D) delete [] j - This option is correct. The new operator with [] was used to allocate an array of characters, so the delete[] operator should be used to deallocate the memory. This will ensure that the entire array is deallocated properly.

The correct answer is Option D. This option is correct because it uses the appropriate delete[] operator to deallocate the dynamically allocated array of characters.

  1. The program should be started with root privileges. Then it should use setuid(UID) to change privileges between root and another account.

  2. The program should be started with root privileges. Then it should use seteuid(UID) to change privileges between root and another account.

  3. Starting the program as root is a security risk. The program should run with least privileges and obtain root using seteuid(UID) whenever necessary.

  4. The program has to run with root privileges entirely. Once root privileges are dropped they cannot be regained.


Correct Option: B