1. C++ program with a heap buffer overflow

a. Download the following program that exploits a shortcoming of STL vectors (which uses the heap) and iterators. Compile and run the program. Try at least three different scenarios:

  • No command line argument.
  • A small command line argument larger than 10 but around 20 - 30.
  • A very large command line argument.

Explain what happened in each case. Did you receive a memory fault in the last case? (Depends on the IDE or OS you use.)

How could the problem be fixed?

b. Write a program in Java that dynamically allocates a large integer array.

  • Start with an array with at least 100 million elements. Increase the size (number of elements) of the array until an exception is generated. The operating system should generate a hardware interrupt when the amount of user addressable space has been exhausted. Java should pass this interrupt on as an exception.
  • How much memory was used before the exception was generated? You can calculate the number of bytes by multiplying the sizeof(int) times the total number of integers requested. You should print out this value each time the number of elments was increased.
  • Is naively running out of heap memory an exploitable vulnerability in Java?
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.