An article of manufacture comprising a non-transitory computer readable storage medium comprising program code tangibly embodied thereon, which when executed by a computer, performs method steps for protecting from buffer overflow vulnerability due to placement new constructs, the method steps comprising:
- determining whether an instruction in a program is a placement new instruction which would result in an object overwriting contents in a memory area;
- and
- selecting a method for preventing buffer overflow if it is determined that the instruction is the placement new instruction which would result in the object overwriting the contents in the memory area;
- wherein the selection of the method is based on at least one predetermined policy;
- wherein the method is selected from at least first and second methods;
- wherein the first method takes into consideration that a given execution of the program will not reach all parts of the object and comprises:
- populating a portion of the memory area allocated by the placement new instruction with less than a total of the object;
- and
- populating a remaining space of the memory area originally allocated to a remaining portion of the total of the object with a first handler routine;
- and
- wherein the second method comprises:
- allocating portions of the object to respective memory regions, wherein the respective memory regions are in different systems;
- and
- invoking a second handler routine if enough free space is not available to accommodate the total of the object.