Software Development Security

A function computes a buffer size by multiplying an attacker-supplied record count by the record size. The product wraps to a small value, and the copy loop then writes every record into the undersized buffer. What is the root cause of the undersized allocation?

Show the answer

Correct answerD. Integer overflow

AWhy not this: The overflowing write is the result of the undersized buffer, not what caused the buffer to be too small.

BWhy not this: Use-after-free involves accessing memory after it has been released, which does not happen here.

CWhy not this: Format string flaws arise when untrusted input is used as a format specifier, which is not involved.

DWhy this is right: The arithmetic wraps past the integer's maximum, producing a small size that the copy loop then exceeds.

The multiplication exceeds the integer's range and wraps, so the allocation is too small. This integer overflow enables the later heap overflow. The heap overflow is the consequence of the undersized allocation, not the cause.