Consider the following pseudo code function:

Core Answer

To test the given factorial() function for a stack overflow error, you should use a large positive integer as input.

Reasons and Explanations

  • Reason 1: Recursion Depth and Stack Overflow: The factorial() function is implemented recursively. Each recursive call adds a new frame to the call stack. If the input n is very large, the function will call itself many times before reaching the base case (n=0 or n=1). This can lead to the call stack exceeding its maximum size, resulting in a stack overflow error.
  • Reason 2: Identifying the Critical Input: A small input value (e.g., 5, 10) will result in a limited number of recursive calls, which is unlikely to cause a stack overflow. However, a large input value (e.g., 10000, 100000, or even larger, depending on the system’s stack size) will cause a very deep recursion, potentially exceeding the stack limit. The exact value that triggers the overflow depends on the system’s memory configuration and stack size limits.

Summary

Using a large positive integer as input for the factorial() function will maximize the recursion depth and increase the likelihood of triggering a stack overflow error, thus effectively testing the code for this vulnerability.

Read more here: Source link