answersLogoWhite

0

How do you fix buffer overflow?

Updated: 12/22/2022
User Avatar

Wiki User

9y ago

Best Answer

The problem with buffers is that you need to keep track of the amount of memory physically allocated to the buffer. This means a buffer has at least two variables: a reference to the allocation and its size. If the buffer size is constant it is obviously easier to keep track of its length but if it is variable you must ensure the size variable is kept in sync with the actual buffer length. The easiest way to keep track of buffer lengths is to store the buffer and its length in a structure:

struct data {

char * buffer;

int length;

};

You still have to ensure the length is kept in sync with the buffer, but now the two can be treated as being a single entity, making it much easier to pass buffers into and out of functions.

However, a better approach is to use object-oriented programming to encapsulate the buffer and its length, thus hiding the details of the representation:

std::vector<char> buffer;

You no longer have to keep track of the length because that is encapsulated within the vector. Every time you push/pop values, the size is incremented or decremented accordingly. All memory management is also handled by the vector, so new memory is allocated as and when required, and the size is adjusted accordingly. All you have to do is rewrite your functions to make use of a vector rather than a buffer.

User Avatar

Wiki User

9y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you fix buffer overflow?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you fix buffer overflow with McAfee?

Only issue with the mcafee antivirus itself. Just reinstall the antivirus to resolve the issue.


What is the Morris finger worm?

Buffer overflow errors


What is the reliable command buffer overflow in modern warfare 3 and how do i fix it?

It happens to pc and ps3 ppm as far as I know. It happened to me while playing spec ops.


Which of the following can be used for protection against buffer overflow attacks?

Input validation


Does the AMD FX-55 CPU have NX buffer overflow protection?

Yes.


What is the meaning of stack-based buffer overflow?

A buffer overflow occurs when you put more stuff into it than it can hold. For a stack, it means you put or pushed onto the stack more information than the size of the stack.If I have a stack that can hold 10 entries, then putting 11 in the stack will overflow it.


What can trigger a buffer overflow?

A buffer overflow occurs when a program attempts to write data to a buffer, but exceeds the boundaries of the buffer, similar to Java's "Array Out of Bounds Exception." This could happen with poorly written code that fails to check for the end of the buffer, or it could be exploited maliciously. One exploitative example would be a stack buffer overflow, in which data is copied to a local variable on the stack. But if the data is larger than the local variable can contain, the extra data will "spill over" onto nearby memory. This would allow one to overwrite data that was not intended to be altered.


Stack overflow at line 597?

how to fix stack overflow at line 597


what type of attack that can be avoided by using proper input validation rules?

buffer overflow


How did binding buffer get its name?

A binding buffer is a substance used in chromatography to fix a specific compound.For example this buffer can be linked to a protein.


How do you avoid data buffer overflow in transport layer?

There is a special bit signaling if the buffer is full. If the buffer is full the bit signals "BUSY" as result transmission stops until the bit changes to "READY" and transmission resumes.


How do you fix stack overflow on a computer?

A quick fix for stack overflow problems is to run a registry cleaning program. There are a lot of them out there so just search for Registry Cleaner.