Skip to content

Commit 3276a08

Browse files
Fix unit test build errors under -Werror (#5686)
Co-authored-by: Carol Yeh <69044490+CarolYeh910@users.noreply.github.com>
1 parent 1f5dab0 commit 3276a08

9 files changed

+40
-17
lines changed

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,11 @@ if (BUILD_TESTING)
579579
target_compile_options(${test_case_name} PRIVATE
580580
-Wall -Wimplicit -Wunused -Wcomment -Wchar-subscripts -Wuninitialized
581581
-Wshadow -Wcast-align -Wwrite-strings -Wformat-security
582-
-Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-deprecated -std=gnu99
582+
-Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-deprecated -std=gnu99 -Wno-missing-braces
583583
)
584+
if (UNSAFE_TREAT_WARNINGS_AS_ERRORS)
585+
target_compile_options(${test_case_name} PRIVATE -Werror)
586+
endif()
584587
if (S2N_LTO)
585588
target_compile_options(${test_case_name} PRIVATE -flto)
586589
endif()

tests/unit/s2n_fork_generation_number_test.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ static int s2n_unit_test_fork_check_threads_first(uint64_t parent_process_fgn)
173173
return S2N_SUCCESS;
174174
}
175175

176+
#if S2N_CLONE_SUPPORTED
176177
static int s2n_unit_test_clone_child_process(void *parent_process_fgn)
177178
{
178179
/* In child */
@@ -191,6 +192,7 @@ static int s2n_unit_test_clone_child_process(void *parent_process_fgn)
191192

192193
exit(EXIT_SUCCESS);
193194
}
195+
#endif
194196

195197
#define PROCESS_CHILD_STACK_SIZE (1024 * 1024) /* Suggested by clone() man page... */
196198
static int s2n_unit_test_clone(uint64_t parent_process_fgn)

tests/unit/s2n_handshake_type_test.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* permissions and limitations under the License.
1414
*/
1515

16+
#include <stdint.h>
1617
#include <sys/param.h>
1718

1819
#include "s2n_test.h"
@@ -36,7 +37,7 @@ int main(int argc, char **argv)
3637
EXPECT_TRUE(S2N_FIRST_TLS12_HANDSHAKE_FLAG < S2N_LAST_TLS12_HANDSHAKE_FLAG);
3738
EXPECT_EQUAL(S2N_FIRST_TLS13_HANDSHAKE_FLAG, S2N_LAST_COMMON_HANDSHAKE_FLAG * 2);
3839
EXPECT_TRUE(S2N_FIRST_TLS13_HANDSHAKE_FLAG < S2N_LAST_TLS13_HANDSHAKE_FLAG);
39-
EXPECT_EQUAL(MAX(S2N_LAST_TLS12_HANDSHAKE_FLAG, S2N_LAST_TLS13_HANDSHAKE_FLAG), S2N_HANDSHAKES_COUNT / 2);
40+
EXPECT_EQUAL(MAX((uint32_t) S2N_LAST_TLS12_HANDSHAKE_FLAG, (uint32_t) S2N_LAST_TLS13_HANDSHAKE_FLAG), S2N_HANDSHAKES_COUNT / 2);
4041

4142
/* Test s2n_handshake_type_reset */
4243
{

tests/unit/s2n_mem_usage_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ int main(int argc, char **argv)
192192

193193
if (kbs_per_conn != expected_kbs_per_conn) {
194194
printf("\nExpected KB per connection: %i\n", expected_kbs_per_conn);
195-
printf("\nActual KB per connection: %li\n", kbs_per_conn);
195+
printf("\nActual KB per connection: %zi\n", kbs_per_conn);
196196
printf("This is a %.2f%% change\n",
197197
(kbs_per_conn - expected_kbs_per_conn) * 100.0 / expected_kbs_per_conn);
198198

tests/unit/s2n_random_test.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ struct random_communication {
7272
static void s2n_verify_child_exit_status(pid_t proc_pid, int expected_status)
7373
{
7474
int status = 0;
75-
#if defined(S2N_CLONE_SUPPORTED)
75+
#if S2N_CLONE_SUPPORTED
7676
EXPECT_EQUAL(waitpid(proc_pid, &status, __WALL), proc_pid);
7777
#else
7878
/* __WALL is not relevant when clone() is not supported
@@ -446,6 +446,7 @@ static S2N_RESULT s2n_fork_test(
446446
return S2N_RESULT_OK;
447447
}
448448

449+
#if S2N_CLONE_SUPPORTED
449450
static int s2n_clone_tests_child_process(void *ipc)
450451
{
451452
struct random_communication *ipc_ptr = (struct random_communication *) ipc;
@@ -459,13 +460,14 @@ static int s2n_clone_tests_child_process(void *ipc)
459460
* statement because we are in a non-void return type function. */
460461
return EXIT_SUCCESS;
461462
}
463+
#endif
462464

463465
#define PROCESS_CHILD_STACK_SIZE (1024 * 1024) /* Suggested by clone() man page... */
464466
static S2N_RESULT s2n_clone_tests(
465467
S2N_RESULT (*s2n_get_random_data_cb)(struct s2n_blob *blob),
466468
S2N_RESULT (*s2n_get_random_data_cb_clone)(struct s2n_blob *blob))
467469
{
468-
#if defined(S2N_CLONE_SUPPORTED)
470+
#if S2N_CLONE_SUPPORTED
469471

470472
int proc_id = 0;
471473
int pipes[2];

tests/unit/s2n_safety_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ static int success_memcpy()
128128

129129
static int failure_memcpy()
130130
{
131-
char src[1024];
131+
char src[1024] = { 0 };
132132
char *ptr = NULL;
133133

134134
POSIX_CHECKED_MEMCPY(ptr, src, 1024);

tests/unit/s2n_tls12_handshake_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ int main(int argc, char **argv)
107107
{
108108
struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT);
109109
conn->actual_protocol_version = S2N_TLS12;
110-
EXPECT_EQUAL(ACTIVE_STATE_MACHINE(conn), state_machine);
111-
EXPECT_EQUAL(ACTIVE_HANDSHAKES(conn), handshakes);
110+
EXPECT_EQUAL(&ACTIVE_STATE_MACHINE(conn)[0], &state_machine[0]);
111+
EXPECT_EQUAL(&ACTIVE_HANDSHAKES(conn)[0], &handshakes[0]);
112112
EXPECT_SUCCESS(s2n_connection_free(conn));
113113
};
114114

tests/unit/s2n_tls13_handshake_state_machine_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ int main(int argc, char **argv)
305305
struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT);
306306
conn->actual_protocol_version = S2N_TLS13;
307307
EXPECT_OK(s2n_conn_choose_state_machine(conn, S2N_TLS13));
308-
EXPECT_EQUAL(ACTIVE_STATE_MACHINE(conn), tls13_state_machine);
309-
EXPECT_EQUAL(ACTIVE_HANDSHAKES(conn), tls13_handshakes);
308+
EXPECT_EQUAL(&ACTIVE_STATE_MACHINE(conn)[0], &tls13_state_machine[0]);
309+
EXPECT_EQUAL(&ACTIVE_HANDSHAKES(conn)[0], &tls13_handshakes[0]);
310310
EXPECT_SUCCESS(s2n_connection_free(conn));
311311
};
312312

tests/unit/s2n_x509_validator_test.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@
2020
#include "testlib/s2n_testlib.h"
2121
#include "tls/s2n_certificate_keys.h"
2222

23-
static int mock_time(void *data, uint64_t *timestamp)
24-
{
25-
*timestamp = *(uint64_t *) data;
26-
return 0;
27-
}
28-
2923
static int fetch_expired_after_ocsp_timestamp(void *data, uint64_t *timestamp)
3024
{
3125
/* 2250-01-01 */
@@ -41,6 +35,11 @@ static int fetch_early_expired_after_ocsp_timestamp(void *data, uint64_t *timest
4135
}
4236

4337
#if S2N_OCSP_STAPLING_SUPPORTED
38+
static int mock_time(void *data, uint64_t *timestamp)
39+
{
40+
*timestamp = *(uint64_t *) data;
41+
return 0;
42+
}
4443
static int fetch_invalid_before_ocsp_timestamp(void *data, uint64_t *timestamp)
4544
{
4645
/* 2015-02-27 */
@@ -128,7 +127,23 @@ static bool s2n_supports_large_time_t()
128127
static bool s2n_libcrypto_supports_2050()
129128
{
130129
ASN1_TIME *utc_time = ASN1_UTCTIME_set(NULL, 0);
131-
time_t time_2050 = 2524608000;
130+
if (!utc_time) {
131+
return false;
132+
}
133+
134+
/* The `32BitBuildAndUnit` job in s2nGeneralBatch runs on a 32-bit system
135+
* where time_t cannot represent the year 2050 (2524608000) and triggers
136+
* -Wconstant-conversion (treated as an error).
137+
*
138+
* The libcrypto used by the job (i386-linux-gnu) does support year 2050.
139+
* Return true to skip the `X509_cmp_time` call.
140+
*/
141+
if (sizeof(time_t) < 8) {
142+
ASN1_STRING_free(utc_time);
143+
return true;
144+
}
145+
146+
time_t time_2050 = (time_t) 2524608000LL;
132147
int result = X509_cmp_time(utc_time, &time_2050);
133148
ASN1_STRING_free(utc_time);
134149
return (result != 0);

0 commit comments

Comments
 (0)