PrepAway - Latest Free Exam Questions & Answers

How can you protect/fix the problem of your application as shown above?

Buffer X is an Accounting application module for company can contain 200 characters. The programmer makes an assumption that 200 characters are more than enough. Because there were no proper boundary checks being conducted. Dave decided to insert 400 characters into the 200-character buffer which overflows the buffer. Below is the code snippet:

Void func (void)

{int I; char buffer [200];

for (I=0; I<400; I++)

buffer (I)= `A’;

return;

}

How can you protect/fix the problem of your application as shown above? (Choose two)

PrepAway - Latest Free Exam Questions & Answers

A.
Because the counter starts with 0, we would stop when the counter is less then 200.

B.
Because the counter starts with 0, we would stop when the counter is more than 200.

C.
Add a separate statement to signify that if we have written 200 characters to the buffer, the stack should stop because it cannot hold any more data.

D.
Add a separate statement to signify that if we have written less than 200 characters to the buffer, the stack should stop because it cannot hold any more data.

Explanation:
I=199 would be the character number 200. The stack holds exact 200 characters so there is no need to stop before 200.


Leave a Reply