From 0f4a06594ed457869e4bf93cdacfa6e6c4f0383f Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Mon, 12 Nov 2018 16:02:33 -0700 Subject: [PATCH 1/2] cast to resolve warning, check size of time_t, and check for null test case --- configure.ac | 1 + src/internal.c | 2 +- tests/api.c | 2 +- wolfcrypt/test/test.c | 3 ++- wolfssl/wolfcrypt/wc_port.h | 6 ++++++ 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 3c4e91373..2d6ec7a65 100644 --- a/configure.ac +++ b/configure.ac @@ -66,6 +66,7 @@ AS_IF([ test -n "$CFLAG_VISIBILITY" ], [ # checks to fail. AC_CHECK_SIZEOF([long long]) AC_CHECK_SIZEOF([long]) +AC_CHECK_SIZEOF([time_t]) AC_CHECK_TYPES([__uint128_t]) AC_CHECK_FUNCS([gethostbyname getaddrinfo gettimeofday gmtime_r inet_ntoa memset socket]) AC_CHECK_HEADERS([arpa/inet.h fcntl.h limits.h netdb.h netinet/in.h stddef.h sys/ioctl.h sys/socket.h sys/time.h errno.h]) diff --git a/src/internal.c b/src/internal.c index b584f0495..fa4f706ff 100644 --- a/src/internal.c +++ b/src/internal.c @@ -4204,7 +4204,7 @@ int InitSSL_Suites(WOLFSSL* ssl) haveRSA = 1; #endif #ifndef NO_PSK - havePSK = ssl->options.havePSK; + havePSK = (byte)ssl->options.havePSK; #endif /* NO_PSK */ #ifdef HAVE_ANON haveAnon = ssl->options.haveAnon; diff --git a/tests/api.c b/tests/api.c index 6a67eb115..4d379d249 100644 --- a/tests/api.c +++ b/tests/api.c @@ -911,7 +911,7 @@ static int test_cm_load_ca_file(const char* ca_cert_file) if (ret == 0) { /* test loading DER */ ret = wc_PemToDer(cert_buf, cert_sz, CA_TYPE, &pDer, NULL, NULL, NULL); - if (ret == 0) { + if (ret == 0 && pDer != NULL) { ret = test_cm_load_ca_buffer(pDer->buffer, pDer->length, WOLFSSL_FILETYPE_ASN1); diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index c6c88024b..74c625b1b 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -10117,7 +10117,8 @@ static int rsa_certgen_test(RsaKey* key, RsaKey* keypub, WC_RNG* rng, byte* tmp) fclose(file3); #endif /* USE_CERT_BUFFERS */ - #ifndef NO_FILESYSTEM + #if !defined(NO_FILESYSTEM) && !defined(USE_CERT_BUFFERS_1024) && \ + !defined(USE_CERT_BUFFERS_2048) && !defined(NO_ASN) ret = wc_SetAltNames(myCert, rsaCaCertFile); if (ret != 0) { ERROR_OUT(-6931, exit_rsa); diff --git a/wolfssl/wolfcrypt/wc_port.h b/wolfssl/wolfcrypt/wc_port.h index 62db45c87..73cce5657 100755 --- a/wolfssl/wolfcrypt/wc_port.h +++ b/wolfssl/wolfcrypt/wc_port.h @@ -478,6 +478,12 @@ WOLFSSL_API int wolfCrypt_Cleanup(void); #endif #endif +#ifdef SIZEOF_TIME_T + #if SIZEOF_TIME_T < 8 + #undef TIME_T_NOT_LONG + #define TIME_T_NOT_LONG + #endif +#endif /* Map default time functions */ #if !defined(XTIME) && !defined(TIME_OVERRIDES) && !defined(USER_TIME) From ee30b2b4764d093692a16e93ce61db62423100d3 Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Fri, 16 Nov 2018 15:51:38 -0700 Subject: [PATCH 2/2] better name for time_t size macro guard --- IDE/GCC-ARM/README.md | 2 +- tests/api.c | 6 +++--- wolfssl/wolfcrypt/wc_port.h | 13 ++++++++++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/IDE/GCC-ARM/README.md b/IDE/GCC-ARM/README.md index d110c1561..353a3c399 100644 --- a/IDE/GCC-ARM/README.md +++ b/IDE/GCC-ARM/README.md @@ -81,7 +81,7 @@ $ make $ make install ``` -If you are building for a 32-bit architecture, add `-DTIME_T_NOT_LONG` to the +If you are building for a 32-bit architecture, add `-DTIME_T_NOT_64BIT` to the list of CFLAGS. ## Example Build Output diff --git a/tests/api.c b/tests/api.c index 4d379d249..f9bc92997 100644 --- a/tests/api.c +++ b/tests/api.c @@ -18578,7 +18578,7 @@ static void test_wolfSSL_ASN1_TIME_adj(void) const int hour = 60*60; const int mini = 60; const byte asn_utc_time = ASN_UTC_TIME; -#if !defined(TIME_T_NOT_LONG) && !defined(NO_64BIT) +#if !defined(TIME_T_NOT_64BIT) && !defined(NO_64BIT) const byte asn_gen_time = ASN_GENERALIZED_TIME; #endif WOLFSSL_ASN1_TIME *asn_time, *s; @@ -18613,7 +18613,7 @@ static void test_wolfSSL_ASN1_TIME_adj(void) XMEMSET(date_str, 0, sizeof(date_str)); /* Generalized time will overflow time_t if not long */ -#if !defined(TIME_T_NOT_LONG) && !defined(NO_64BIT) +#if !defined(TIME_T_NOT_64BIT) && !defined(NO_64BIT) s = (WOLFSSL_ASN1_TIME*)XMALLOC(sizeof(WOLFSSL_ASN1_TIME), NULL, DYNAMIC_TYPE_OPENSSL); /* GeneralizedTime notation test */ @@ -18628,7 +18628,7 @@ static void test_wolfSSL_ASN1_TIME_adj(void) XFREE(s,NULL,DYNAMIC_TYPE_OPENSSL); XMEMSET(date_str, 0, sizeof(date_str)); -#endif /* !TIME_T_NOT_LONG && !NO_64BIT */ +#endif /* !TIME_T_NOT_64BIT && !NO_64BIT */ /* if WOLFSSL_ASN1_TIME struct is not allocated */ s = NULL; diff --git a/wolfssl/wolfcrypt/wc_port.h b/wolfssl/wolfcrypt/wc_port.h index 73cce5657..c612a24d9 100755 --- a/wolfssl/wolfcrypt/wc_port.h +++ b/wolfssl/wolfcrypt/wc_port.h @@ -474,16 +474,23 @@ WOLFSSL_API int wolfCrypt_Cleanup(void); /* PowerPC time_t is int */ #ifdef __PPC__ - #define TIME_T_NOT_LONG + #define TIME_T_NOT_64BIT #endif #endif #ifdef SIZEOF_TIME_T + /* check if size of time_t from autoconf is less than 8 bytes (64bits) */ #if SIZEOF_TIME_T < 8 - #undef TIME_T_NOT_LONG - #define TIME_T_NOT_LONG + #undef TIME_T_NOT_64BIT + #define TIME_T_NOT_64BIT #endif #endif +#ifdef TIME_T_NOT_LONG + /* one old reference to TIME_T_NOT_LONG in GCC-ARM example README + * this keeps support for the old macro name */ + #undef TIME_T_NOT_64BIT + #define TIME_T_NOT_64BIT +#endif /* Map default time functions */ #if !defined(XTIME) && !defined(TIME_OVERRIDES) && !defined(USER_TIME)