2323#include "crypto/s2n_openssl.h"
2424#include "s2n_test.h"
2525
26+ #define MAX_LIBCRYPTO_NAME_LEN 100
27+
2628int tokenize_s2n_libcrypto (char * s2n_libcrypto , char * * name , char * * version )
2729{
2830 if (name == NULL || version == NULL || s2n_libcrypto == NULL ) {
@@ -44,6 +46,19 @@ int tokenize_s2n_libcrypto(char *s2n_libcrypto, char **name, char **version)
4446 return S2N_SUCCESS ;
4547}
4648
49+ S2N_RESULT s2n_test_lowercase_copy (const char * input , char * destination , size_t max_len )
50+ {
51+ RESULT_ENSURE_REF (input );
52+ RESULT_ENSURE_REF (destination );
53+
54+ for (size_t i = 0 ; i < strlen (input ); i ++ ) {
55+ RESULT_ENSURE_LT (i , max_len );
56+ destination [i ] = tolower (input [i ]);
57+ }
58+
59+ return S2N_RESULT_OK ;
60+ }
61+
4762int main ()
4863{
4964 BEGIN_TEST ();
@@ -69,8 +84,9 @@ int main()
6984 END_TEST ();
7085 }
7186
72- char s2n_libcrypto_copy [100 ] = { 0 };
73- strncpy (s2n_libcrypto_copy , s2n_libcrypto , 99 );
87+ char s2n_libcrypto_copy [MAX_LIBCRYPTO_NAME_LEN ] = { 0 };
88+ EXPECT_TRUE (strlen (s2n_libcrypto ) < MAX_LIBCRYPTO_NAME_LEN );
89+ EXPECT_OK (s2n_test_lowercase_copy (s2n_libcrypto , & s2n_libcrypto_copy [0 ], s2n_array_len (s2n_libcrypto_copy )));
7490 char * name = NULL ;
7591 char * version = NULL ;
7692 EXPECT_SUCCESS (tokenize_s2n_libcrypto (s2n_libcrypto_copy , & name , & version ));
@@ -83,8 +99,9 @@ int main()
8399 EXPECT_TRUE (s2n_libcrypto_is_awslc ());
84100 } else {
85101 /* Any other library should have the name of the library (modulo case) in its version string. */
86- const char * ssleay_version_text = SSLeay_version (SSLEAY_VERSION );
87- EXPECT_NOT_NULL (strcasestr (ssleay_version_text , name ));
102+ char ssleay_version_text [MAX_LIBCRYPTO_NAME_LEN ] = { 0 };
103+ EXPECT_OK (s2n_test_lowercase_copy (SSLeay_version (SSLEAY_VERSION ), & ssleay_version_text [0 ], MAX_LIBCRYPTO_NAME_LEN ));
104+ EXPECT_NOT_NULL (strstr (ssleay_version_text , name ));
88105 }
89106 };
90107
0 commit comments