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

Buffer X in an Accounting application module for Brownies Inc. 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, Bob decided to insert 400 characters into the 200-character buffer. (Overflows the buffer). Below is the code snippet:
How can you protect/fix the problem of your application as shown above?

Buffer X in an Accounting application module for Brownies Inc. 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, Bob decided to insert 400 characters into the 200-character buffer. (Overflows the buffer). Below is the code snippet:

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

A.
Because the counter starts with 0, we would stop when the counter is less than 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 less than 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 200 characters to the buffer, the stack should stop because it cannot hold any more data “Pass Any



Leave a Reply 5

Your email address will not be published. Required fields are marked *


Rak

Rak

A seems to be wrong, as 0 is also less than 200, so we should not stop at 0 right?

Me

Me

I think they are suggesting 0-199, so we stop before 200

Unethica

Unethica

They are talking about the condition statement in the for loop. It is worded poorly though.

Sam

Sam

I see that only D is correct as the counter will not stop at 200; the condition is less than 400.