N
Nephi Immortal
When you place a string between two quote marks in the function’s
parameter, how many characters should be limited? The character
length should be 256.
For example
void Test( char* text ) { …. }
Test( “0123456789” );
If character length is to be 512, 1024, or 4096, string is too big to
fit into the stack.
If anyone plants virus program into memory, it is possible to cause
that buffer overruns unless null terminator is overwritten with new
character value.
The condition is shown *ptr != ‘\0’ is unsafe. More safe condition
should be added. If buffer goes past overwritten null terminator,
buffer overruns can be avoided with limited character garbages.
char A[ 256 ] =
"0123456789";
int main()
{
const int BUFFER_SIZE = 256;
char B [ 256 ];
int index = 0;
do
{
B[ index ] = A[ index ];
++index;
}
while( index < BUFFER_SIZE - 1 && A[ index ] != '\0' ); // safe
// while(A[ index ] != '\0' ); // unsafe
B[ index ] = '\0';
return 0;
}
parameter, how many characters should be limited? The character
length should be 256.
For example
void Test( char* text ) { …. }
Test( “0123456789” );
If character length is to be 512, 1024, or 4096, string is too big to
fit into the stack.
If anyone plants virus program into memory, it is possible to cause
that buffer overruns unless null terminator is overwritten with new
character value.
The condition is shown *ptr != ‘\0’ is unsafe. More safe condition
should be added. If buffer goes past overwritten null terminator,
buffer overruns can be avoided with limited character garbages.
char A[ 256 ] =
"0123456789";
int main()
{
const int BUFFER_SIZE = 256;
char B [ 256 ];
int index = 0;
do
{
B[ index ] = A[ index ];
++index;
}
while( index < BUFFER_SIZE - 1 && A[ index ] != '\0' ); // safe
// while(A[ index ] != '\0' ); // unsafe
B[ index ] = '\0';
return 0;
}