From dd0aae92e0c46fbd04d70577dddbbea79ff39574 Mon Sep 17 00:00:00 2001
From: Paul Bakker
Date: Thu, 17 Apr 2014 16:06:37 +0200
Subject: [PATCH] Replaced strcpy() with strncpy() in tests suites
---
tests/suites/test_suite_base64.function | 6 +++---
tests/suites/test_suite_md.function | 20 +++++++++-----------
tests/suites/test_suite_mdx.function | 8 ++++----
3 files changed, 16 insertions(+), 18 deletions(-)
diff --git a/tests/suites/test_suite_base64.function b/tests/suites/test_suite_base64.function
index 27b6c134c..b8ddba72a 100644
--- a/tests/suites/test_suite_base64.function
+++ b/tests/suites/test_suite_base64.function
@@ -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 )
{
diff --git a/tests/suites/test_suite_md.function b/tests/suites/test_suite_md.function
index 4b5921f7c..7b6f9e5b1 100644
--- a/tests/suites/test_suite_md.function
+++ b/tests/suites/test_suite_md.function
@@ -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 );
diff --git a/tests/suites/test_suite_mdx.function b/tests/suites/test_suite_mdx.function
index 0676d8200..24fb32894 100644
--- a/tests/suites/test_suite_mdx.function
+++ b/tests/suites/test_suite_mdx.function
@@ -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 );