From 894059f675c4425a07981b35809b43f09e18ef2d Mon Sep 17 00:00:00 2001 From: David Garske Date: Tue, 15 Feb 2022 14:52:25 -0800 Subject: [PATCH] Added missing `string.h` for `strcasestr`. --- btle/btle-sim.h | 5 +++++ btle/ecies/ecc-client.c | 16 ++++++++++++---- btle/ecies/ecc-server.c | 12 ++++++++---- btle/tls/client-tls13-btle.c | 10 ++++++---- btle/tls/server-tls13-btle.c | 5 ++--- 5 files changed, 33 insertions(+), 15 deletions(-) diff --git a/btle/btle-sim.h b/btle/btle-sim.h index 04861c3b..60dcf7ba 100644 --- a/btle/btle-sim.h +++ b/btle/btle-sim.h @@ -23,6 +23,11 @@ #define BTLE_MSG_MAX_SIZE 1024 #define BTLE_BLOCK_SIZE 16 +#define _GNU_SOURCE +#include /* for strcasestr */ + +#define EXIT_STRING "EXIT" + typedef enum { BTLE_PKT_TYPE_NULL, BTLE_PKT_TYPE_KEY, diff --git a/btle/ecies/ecc-client.c b/btle/ecies/ecc-client.c index 431b1261..8f3ff5d7 100644 --- a/btle/ecies/ecc-client.c +++ b/btle/ecies/ecc-client.c @@ -19,17 +19,19 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ +#include "../btle-sim.h" + #ifndef WOLFSSL_USER_SETTINGS #include #endif #include #include #include -#include "../btle-sim.h" int main(int argc, char** argv) { - int ret; + int ret = 0; +#ifdef HAVE_ECC_ENCRYPT WC_RNG rng; ecEncCtx* cliCtx = NULL; void* devCtx = NULL; @@ -153,7 +155,10 @@ int main(int argc, char** argv) /* get message to send */ printf("Enter text to send:\n"); plainSz = sizeof(plain)-1; - fgets((char*)plain, plainSz, stdin); + if (fgets((char*)plain, plainSz, stdin) == NULL) { + printf("stdin get failed\n"); + goto cleanup; + } plainSz = strlen((char*)plain); /* pad message at 16 bytes for AES block size */ ret = btle_msg_pad(plain, (int*)&plainSz, devCtx); @@ -196,7 +201,7 @@ int main(int argc, char** argv) printf("Recv %d: %s\n", plainSz, plain); /* check for exit flag */ - if (strcasestr((char*)plain, "EXIT")) { + if (strcasestr((char*)plain, EXIT_STRING)) { printf("Exit, closing connection\n"); break; } @@ -216,5 +221,8 @@ cleanup: wolfCrypt_Cleanup(); +#else + printf("Please compile wolfSSL with --enable-eccencrypt or HAVE_ECC_ENCRYPT\n"); +#endif return ret; } diff --git a/btle/ecies/ecc-server.c b/btle/ecies/ecc-server.c index efdc6223..72d168fa 100644 --- a/btle/ecies/ecc-server.c +++ b/btle/ecies/ecc-server.c @@ -19,17 +19,19 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ +#include "../btle-sim.h" + #ifndef WOLFSSL_USER_SETTINGS #include #endif #include #include #include -#include "../btle-sim.h" int main(int argc, char** argv) { - int ret; + int ret = 0; +#ifdef HAVE_ECC_ENCRYPT WC_RNG rng; ecEncCtx* srvCtx = NULL; void* devCtx = NULL; @@ -189,7 +191,7 @@ int main(int argc, char** argv) } /* check for exit flag */ - if (strcasestr((char*)plain, "EXIT")) { + if (strcasestr((char*)plain, EXIT_STRING)) { printf("Exit, closing connection\n"); break; } @@ -208,6 +210,8 @@ cleanup: btle_close(devCtx); wolfCrypt_Cleanup(); - +#else + printf("Please compile wolfSSL with --enable-eccencrypt or HAVE_ECC_ENCRYPT\n"); +#endif return ret; } diff --git a/btle/tls/client-tls13-btle.c b/btle/tls/client-tls13-btle.c index e268fa27..274b664e 100644 --- a/btle/tls/client-tls13-btle.c +++ b/btle/tls/client-tls13-btle.c @@ -23,6 +23,7 @@ * Example TLSv1.3 client over BTLE */ +#include "../btle-sim.h" #ifndef WOLFSSL_USER_SETTINGS #include @@ -31,8 +32,6 @@ #include #include -#include "../btle-sim.h" - #define CERT_FILE "../../certs/client-cert.pem" #define KEY_FILE "../../certs/client-key.pem" #define CA_FILE "../../certs/ca-cert.pem" @@ -171,7 +170,10 @@ int main(int argc, char** argv) printf("Enter text to send:\n"); plainSz = sizeof(plain)-1; - fgets((char*)plain, plainSz, stdin); + if (fgets((char*)plain, plainSz, stdin) == NULL) { + printf("stdin get failed\n"); + goto done; + } plainSz = strlen((char*)plain); do { @@ -187,7 +189,7 @@ int main(int argc, char** argv) printf("Read (%d): %s\n", ret, plain); /* check for exit flag */ - if (strcasestr((char*)plain, "EXIT")) { + if (strcasestr((char*)plain, EXIT_STRING)) { printf("Exit, closing connection\n"); break; } diff --git a/btle/tls/server-tls13-btle.c b/btle/tls/server-tls13-btle.c index 79f1548b..d365b473 100644 --- a/btle/tls/server-tls13-btle.c +++ b/btle/tls/server-tls13-btle.c @@ -23,6 +23,7 @@ * Example TLS v1.3 server over BTLE */ +#include "../btle-sim.h" #ifndef WOLFSSL_USER_SETTINGS #include @@ -31,8 +32,6 @@ #include #include -#include "../btle-sim.h" - #define CERT_FILE "../../certs/server-cert.pem" #define KEY_FILE "../../certs/server-key.pem" #define CA_FILE "../../certs/client-cert.pem" @@ -178,7 +177,7 @@ int main(int argc, char** argv) printf("Sent (%d): %s\n", ret, echoBuffer); /* check for exit flag */ - if (strcasestr((char*)echoBuffer, "EXIT")) { + if (strcasestr((char*)echoBuffer, EXIT_STRING)) { printf("Exit, closing connection\n"); break; }