Skip to content
代码片段 群组 项目
提交 dd0aae92 编辑于 作者: Paul Bakker's avatar Paul Bakker
浏览文件

Replaced strcpy() with strncpy() in tests suites

上级 b6487dad
No related branches found
No related tags found
无相关合并请求
......@@ -18,7 +18,7 @@ void base64_encode( char *src_string, char *dst_string, int dst_buf_size,
memset(src_str, 0x00, 1000);
memset(dst_str, 0x00, 1000);
strcpy( (char *) src_str, src_string );
strncpy( (char *) src_str, src_string, sizeof(src_str) - 1 );
TEST_ASSERT( base64_encode( dst_str, &len, src_str, strlen( (char *) src_str ) ) == result );
if( result == 0 )
{
......@@ -37,8 +37,8 @@ void base64_decode( char *src_string, char *dst_string, int result )
memset(src_str, 0x00, 1000);
memset(dst_str, 0x00, 1000);
strcpy( (char *) src_str, src_string );
strncpy( (char *) src_str, src_string, sizeof(src_str) - 1 );
TEST_ASSERT( res = base64_decode( dst_str, &len, src_str, strlen( (char *) src_str ) ) == result );
if( result == 0 )
{
......
......@@ -70,9 +70,8 @@ void md_text( char *text_md_name, char *text_src_string, char *hex_hash_string )
memset(hash_str, 0x00, 1000);
memset(output, 0x00, 100);
strcpy( (char *) src_str, text_src_string );
strncpy( (char *) md_name, text_md_name, 100 );
strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 );
strncpy( (char *) md_name, text_md_name, sizeof(md_name) - 1 );
md_info = md_info_from_string(md_name);
TEST_ASSERT( md_info != NULL );
......@@ -98,7 +97,7 @@ void md_hex( char *text_md_name, char *hex_src_string, char *hex_hash_string )
memset(hash_str, 0x00, 10000);
memset(output, 0x00, 100);
strncpy( (char *) md_name, text_md_name, 100 );
strncpy( (char *) md_name, text_md_name, sizeof(md_name) - 1 );
md_info = md_info_from_string(md_name);
TEST_ASSERT( md_info != NULL );
......@@ -128,9 +127,8 @@ void md_text_multi( char *text_md_name, char *text_src_string,
memset(hash_str, 0x00, 1000);
memset(output, 0x00, 100);
strcpy( (char *) src_str, text_src_string );
strncpy( (char *) md_name, text_md_name, 100 );
strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 );
strncpy( (char *) md_name, text_md_name, sizeof(md_name) - 1 );
md_info = md_info_from_string(md_name);
TEST_ASSERT( md_info != NULL );
TEST_ASSERT ( 0 == md_init_ctx( &ctx, md_info ) );
......@@ -164,7 +162,7 @@ void md_hex_multi( char *text_md_name, char *hex_src_string,
memset(hash_str, 0x00, 10000);
memset(output, 0x00, 100);
strncpy( (char *) md_name, text_md_name, 100 );
strncpy( (char *) md_name, text_md_name, sizeof(md_name) - 1 );
md_info = md_info_from_string(md_name);
TEST_ASSERT( md_info != NULL );
TEST_ASSERT ( 0 == md_init_ctx( &ctx, md_info ) );
......@@ -201,7 +199,7 @@ void md_hmac( char *text_md_name, int trunc_size, char *hex_key_string,
memset(hash_str, 0x00, 10000);
memset(output, 0x00, 100);
strncpy( (char *) md_name, text_md_name, 100 );
strncpy( (char *) md_name, text_md_name, sizeof(md_name) - 1 );
md_info = md_info_from_string( md_name );
TEST_ASSERT( md_info != NULL );
......@@ -234,7 +232,7 @@ void md_hmac_multi( char *text_md_name, int trunc_size, char *hex_key_string,
memset(hash_str, 0x00, 10000);
memset(output, 0x00, 100);
strncpy( (char *) md_name, text_md_name, 100 );
strncpy( (char *) md_name, text_md_name, sizeof(md_name) - 1 );
md_info = md_info_from_string( md_name );
TEST_ASSERT( md_info != NULL );
TEST_ASSERT ( 0 == md_init_ctx( &ctx, md_info ) );
......@@ -278,7 +276,7 @@ void md_file( char *text_md_name, char *filename, char *hex_hash_string )
memset(hash_str, 0x00, 1000);
memset(output, 0x00, 100);
strncpy( (char *) md_name, text_md_name, 100 );
strncpy( (char *) md_name, text_md_name, sizeof(md_name) - 1 );
md_info = md_info_from_string( md_name );
TEST_ASSERT( md_info != NULL );
......
......@@ -16,7 +16,7 @@ void md2_text( char *text_src_string, char *hex_hash_string )
memset( hash_str, 0x00, sizeof hash_str );
memset( output, 0x00, sizeof output );
strcpy( (char *) src_str, text_src_string );
strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 );
md2( src_str, strlen( (char *) src_str ), output );
hexify( hash_str, output, sizeof output );
......@@ -36,7 +36,7 @@ void md4_text( char *text_src_string, char *hex_hash_string )
memset( hash_str, 0x00, sizeof hash_str );
memset( output, 0x00, sizeof output );
strcpy( (char *) src_str, text_src_string );
strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 );
md4( src_str, strlen( (char *) src_str ), output );
hexify( hash_str, output, sizeof output );
......@@ -56,7 +56,7 @@ void md5_text( char *text_src_string, char *hex_hash_string )
memset( hash_str, 0x00, sizeof hash_str );
memset( output, 0x00, sizeof output );
strcpy( (char *) src_str, text_src_string );
strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 );
md5( src_str, strlen( (char *) src_str ), output );
hexify( hash_str, output, sizeof output );
......@@ -76,7 +76,7 @@ void ripemd160_text( char *text_src_string, char *hex_hash_string )
memset(hash_str, 0x00, sizeof hash_str);
memset(output, 0x00, sizeof output);
strcpy( (char *) src_str, text_src_string );
strncpy( (char *) src_str, text_src_string, sizeof(src_str) - 1 );
ripemd160( src_str, strlen( (char *) src_str ), output );
hexify( hash_str, output, sizeof output );
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册