Skip to content

Commit ec6ca6e

Browse files
authored
build: make CMake test flags more consistent with make (#4392)
1 parent 2178f18 commit ec6ca6e

File tree

5 files changed

+36
-12
lines changed

5 files changed

+36
-12
lines changed

CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ otherwise a crypto target needs to be defined." ON)
2424
option(UNSAFE_TREAT_WARNINGS_AS_ERRORS "Compiler warnings are treated as errors. Warnings may
2525
indicate danger points where you should verify with the S2N-TLS developers that the security of
2626
the library is not compromised. Turn this OFF to ignore warnings." ON)
27+
option(S2N_WERROR_ALL "This option will cause all artifacts linked to libs2n to use the
28+
-Werror setting." OFF)
2729
option(S2N_INTERN_LIBCRYPTO "This ensures that s2n-tls is compiled and deployed with a specific
2830
version of libcrypto by interning the code and hiding symbols. This also enables s2n-tls to be
2931
loaded in an application with an otherwise conflicting libcrypto version." OFF)
@@ -136,7 +138,9 @@ target_compile_options(${PROJECT_NAME} PRIVATE -pedantic -std=gnu99 -Wall -Wimpl
136138
-Wno-missing-braces -Wsign-compare -Wno-strict-prototypes -Wa,--noexecstack
137139
)
138140

139-
if (UNSAFE_TREAT_WARNINGS_AS_ERRORS)
141+
if (S2N_WERROR_ALL)
142+
target_compile_options(${PROJECT_NAME} PUBLIC -Werror)
143+
elseif (UNSAFE_TREAT_WARNINGS_AS_ERRORS)
140144
target_compile_options(${PROJECT_NAME} PRIVATE -Werror )
141145
endif ()
142146

@@ -500,7 +504,11 @@ if (BUILD_TESTING)
500504
find . -name '${test_case_name}.c.o' -exec objcopy --redefine-syms libcrypto.symbols {} \\\;
501505
)
502506
endif()
503-
target_compile_options(${test_case_name} PRIVATE -Wno-implicit-function-declaration -Wno-deprecated -Wunused-result -D_POSIX_C_SOURCE=200809L -std=gnu99)
507+
target_compile_options(${test_case_name} PRIVATE
508+
-Wall -Wimplicit -Wunused -Wcomment -Wchar-subscripts -Wuninitialized
509+
-Wshadow -Wcast-align -Wwrite-strings -Wformat-security
510+
-Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-deprecated
511+
-fPIC -D_POSIX_C_SOURCE=200809L -std=gnu99)
504512
if (S2N_LTO)
505513
target_compile_options(${test_case_name} PRIVATE -flto)
506514
endif()

tests/unit/s2n_build_test.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include "crypto/s2n_openssl.h"
2424
#include "s2n_test.h"
2525

26+
#define MAX_LIBCRYPTO_NAME_LEN 100
27+
2628
int 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+
4762
int 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

tests/unit/s2n_ktls_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ int main(int argc, char **argv)
184184
EXPECT_EQUAL(crypto_info.value.size, sizeof(crypto_info.ciphers.aes_gcm_128));
185185
EXPECT_EQUAL(crypto_info.value.data, (uint8_t *) &crypto_info.ciphers.aes_gcm_128);
186186
s2n_ktls_crypto_info_tls12_aes_gcm_128 *value =
187-
(s2n_ktls_crypto_info_tls12_aes_gcm_128 *) crypto_info.value.data;
187+
(s2n_ktls_crypto_info_tls12_aes_gcm_128 *) (void *) crypto_info.value.data;
188188

189189
EXPECT_EQUAL(test_key.size, sizeof(value->key));
190190
EXPECT_BYTEARRAY_EQUAL(test_key.data, value->key, sizeof(value->key));
@@ -216,7 +216,7 @@ int main(int argc, char **argv)
216216
EXPECT_EQUAL(crypto_info.value.size, sizeof(crypto_info.ciphers.aes_gcm_256));
217217
EXPECT_EQUAL(crypto_info.value.data, (uint8_t *) &crypto_info.ciphers.aes_gcm_256);
218218
s2n_ktls_crypto_info_tls12_aes_gcm_256 *value =
219-
(s2n_ktls_crypto_info_tls12_aes_gcm_256 *) crypto_info.value.data;
219+
(s2n_ktls_crypto_info_tls12_aes_gcm_256 *) (void *) crypto_info.value.data;
220220

221221
EXPECT_EQUAL(test_key.size, sizeof(value->key));
222222
EXPECT_BYTEARRAY_EQUAL(test_key.data, value->key, sizeof(value->key));

tests/unit/s2n_signature_algorithms_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ int main(int argc, char **argv)
239239
/* Test: ECDSA */
240240
{
241241
const struct s2n_signature_scheme *expected = &s2n_ecdsa_sha1;
242-
conn->handshake_params.client_cert_pkey_type = S2N_AUTHENTICATION_ECDSA;
242+
conn->handshake_params.client_cert_pkey_type = S2N_PKEY_TYPE_ECDSA;
243243
EXPECT_SUCCESS(s2n_connection_set_config(conn, client_ecdsa_config));
244244

245245
/* TLS1.1 selects the default */
@@ -256,7 +256,7 @@ int main(int argc, char **argv)
256256
/* Test: RSA */
257257
{
258258
const struct s2n_signature_scheme *expected = &s2n_rsa_pkcs1_md5_sha1;
259-
conn->handshake_params.client_cert_pkey_type = S2N_AUTHENTICATION_RSA;
259+
conn->handshake_params.client_cert_pkey_type = S2N_PKEY_TYPE_RSA;
260260
EXPECT_SUCCESS(s2n_connection_set_config(conn, client_rsa_config));
261261

262262
/* TLS1.1 selects the default */

tests/unit/s2n_x509_validator_test.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@
1313
* permissions and limitations under the License.
1414
*/
1515

16+
#include "crypto/s2n_openssl_x509.h"
1617
#include "s2n_test.h"
1718
#include "testlib/s2n_testlib.h"
1819

19-
DEFINE_POINTER_CLEANUP_FUNC(X509 *, X509_free);
20-
2120
static int mock_time(void *data, uint64_t *timestamp)
2221
{
2322
*timestamp = *(uint64_t *) data;

0 commit comments

Comments
 (0)