assorted cleanups and refactors for C89 conformance, codespell and check-source-text, and consistent heap shim usage.

.github/workflows/codespell.yml: remove */README_jp.txt from "skip" list.

IDE/Renesas/cs+/Projects/t4_demo/README_jp.txt: convert from SHIFT_JIS to UTF-8.

cmake/options.h.in: use "#cmakedefine HAVE_PTHREAD 1" to avoid conflict with config.h.

configure.ac: add --enable-c89, and remove !ENABLED_OPENSSLEXTRA dependency from AM_CONDITIONAL([BUILD_CRYPTONLY],...).

wolfcrypt/src/asn.c: refactor SetOthername() for efficiency, and add PRAGMA_GCC to suppress false positive -Wstringop-overflow associated with -fstack-protector.

wolfssl/wolfcrypt/rsa.h: add WC_ prefixes to RSA_PKCS1_PADDING_SIZE and RSA_PKCS1_OAEP_PADDING_SIZE, and define unprefixed compat aliases only if !OPENSSL_COEXIST.

wolfssl/wolfcrypt/types.h:

  #ifdef WOLF_C89, #define WC_BITFIELD unsigned;
  enhance WOLF_ENUM_DUMMY_LAST_ELEMENT() to include the line number, to construct unique labels given a per-filename argument, to accommodate anonymous enums.

examples/asn1/asn1.c:
examples/client/client.c:
examples/pem/pem.c:
examples/server/server.c:
wolfcrypt/src/sp_dsp32.c:
wolfcrypt/src/wc_port.c:
wolfssl/test.h:

  use XMALLOC/XREALLOC/XFREE consistently, not malloc/realloc/free.

wolfcrypt/benchmark/benchmark.c:
wolfcrypt/src/memory.c:
wolfcrypt/test/test.c:
wolfssl/wolfcrypt/mem_track.h:
wolfssl/wolfcrypt/settings.h:
wolfssl/wolfcrypt/types.h:

  annotate intentional native heap access with "/* native heap */".

wolfcrypt/src/asn.c:
wolfssl/callbacks.h:
wolfssl/openssl/ec.h:
wolfssl/openssl/ssl.h:
wolfssl/wolfcrypt/hpke.h:
wolfssl/wolfcrypt/types.h:

  fix enum trailing commas.

wolfssl/openssl/ec.h:
wolfssl/openssl/evp.h:
wolfssl/openssl/rsa.h:
wolfssl/openssl/ssl.h:

  use WC_BITFIELD in bitfield elements, not byte or word16, to allow for pedantic C89 conformant builds.

wolfssl/openssl/ec.h:
wolfssl/openssl/evp.h:
wolfssl/openssl/pem.h:
wolfssl/openssl/ssl.h:
wolfssl/wolfcrypt/logging.h:
avoid variadic macros wherever possible, and where unavoidable, #ifdef WOLF_NO_VARIADIC_MACROS, define them with empty arg lists, rather than ..., to support Watcom compiler.

wolfssl/wolfcrypt/settings.h: if defined(__WATCOMC__), define WOLF_NO_VARIADIC_MACROS.
This commit is contained in:
Daniel Pouzzner
2024-11-07 22:36:24 -06:00
parent b648d35449
commit aa18bbca55
31 changed files with 342 additions and 290 deletions

View File

@ -66,7 +66,7 @@ static int asn1App_ReadFile(FILE* fp, unsigned char** pdata, word32* plen)
word32 len = 0;
size_t read_len;
/* Allocate a minimum amount. */
unsigned char* data = (unsigned char*)malloc(DATA_INC_LEN);
unsigned char* data = (unsigned char*)XMALLOC(DATA_INC_LEN, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (data != NULL) {
/* Read more data. */
@ -74,7 +74,7 @@ static int asn1App_ReadFile(FILE* fp, unsigned char** pdata, word32* plen)
unsigned char* p;
if (ferror(fp)) {
free(data);
XFREE(data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return IO_FAILED_E;
}
@ -87,10 +87,10 @@ static int asn1App_ReadFile(FILE* fp, unsigned char** pdata, word32* plen)
}
/* Make space for more data to be added to buffer. */
p = (unsigned char*)realloc(data, len + DATA_INC_LEN);
p = (unsigned char*)XREALLOC(data, len + DATA_INC_LEN, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (p == NULL) {
/* Reallocation failed - free current buffer. */
free(data);
XFREE(data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
data = NULL;
break;
}
@ -132,7 +132,7 @@ static int PrintDer(FILE* fp)
/* Print DER/BER. */
ret = wc_Asn1_PrintAll(&asn1, &opts, data, len);
/* Dispose of buffer. */
free(data);
XFREE(data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
return ret;
@ -168,7 +168,7 @@ static int PrintBase64(FILE* fp)
ret = wc_Asn1_PrintAll(&asn1, &opts, data, len);
}
/* Dispose of buffer. */
free(data);
XFREE(data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
return ret;
@ -280,7 +280,7 @@ static int PrintPem(FILE* fp, int pem_skip)
ret = wc_Asn1_PrintAll(&asn1, &opts, data, len);
}
/* Dispose of buffer. */
free(data);
XFREE(data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
return ret;

View File

@ -789,9 +789,9 @@ static int ClientBenchmarkThroughput(WOLFSSL_CTX* ctx, char* host, word16 port,
/* Compare TX and RX buffers */
if (XMEMCMP(tx_buffer, rx_buffer, (size_t)len) != 0) {
free(tx_buffer);
XFREE(tx_buffer, NULL, DYNAMIC_TYPE_TMP_BUFFER);
tx_buffer = NULL;
free(rx_buffer);
XFREE(rx_buffer, NULL, DYNAMIC_TYPE_TMP_BUFFER);
rx_buffer = NULL;
err_sys("Compare TX and RX buffers failed");
}

View File

@ -100,7 +100,7 @@ static int pemApp_ReadFile(FILE* fp, unsigned char** pdata, word32* plen)
word32 len = 0;
size_t read_len;
/* Allocate a minimum amount. */
unsigned char* data = (unsigned char*)malloc(DATA_INC_LEN + BLOCK_SIZE_MAX);
unsigned char* data = (unsigned char*)XMALLOC(DATA_INC_LEN + BLOCK_SIZE_MAX, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (data != NULL) {
/* Read more data. */
@ -116,11 +116,11 @@ static int pemApp_ReadFile(FILE* fp, unsigned char** pdata, word32* plen)
}
/* Make space for more data to be added to buffer. */
p = (unsigned char*)realloc(data, len + DATA_INC_LEN +
BLOCK_SIZE_MAX);
p = (unsigned char*)XREALLOC(data, len + DATA_INC_LEN +
BLOCK_SIZE_MAX, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (p == NULL) {
/* Reallocation failed - free current buffer. */
free(data);
XFREE(data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
data = NULL;
break;
}
@ -560,7 +560,7 @@ static int EncryptDer(unsigned char* in, word32 in_len, char* password,
}
if (ret == 0) {
/* Allocate memory for encrypted DER data. */
*enc = (unsigned char*)malloc(*enc_len);
*enc = (unsigned char*)XMALLOC(*enc_len, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (*enc == NULL) {
ret = 1;
}
@ -613,7 +613,7 @@ static int ConvDerToPem(unsigned char* in, word32 offset, word32 len,
}
if ((ret == 0) && (pem_len > 0)) {
/* Allocate memory to hold PEM encoding. */
pem = (unsigned char*)malloc(pem_len);
pem = (unsigned char*)XMALLOC(pem_len, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (pem == NULL) {
ret = 1;
}
@ -624,7 +624,7 @@ static int ConvDerToPem(unsigned char* in, word32 offset, word32 len,
type);
if (ret <= 0) {
fprintf(stderr, "Could not convert DER to PEM\n");
free(pem);
XFREE(pem, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
if (ret > 0) {
*out = pem;
@ -1025,16 +1025,16 @@ out:
wc_FreeDer(&der);
}
else if (out != NULL) {
free(out);
XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
#if defined(WOLFSSL_DER_TO_PEM) && defined(WOLFSSL_ENCRYPTED_KEYS) && \
!defined(NO_PWDBASED)
if (enc != NULL) {
free(enc);
XFREE(enc, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
#endif
if (in != NULL) {
free(in);
XFREE(in, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
if (ret < 0) {
fprintf(stderr, "%s\n", wc_GetErrorString(ret));

View File

@ -422,7 +422,7 @@ int ServerEchoData(SSL* ssl, int clientfd, int echoData, int block,
size_t xfer_bytes = 0;
char* buffer;
buffer = (char*)malloc((size_t)block);
buffer = (char*)XMALLOC((size_t)block, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (!buffer) {
err_sys_ex(runWithErrors, "Server buffer malloc failed");
}
@ -465,7 +465,7 @@ int ServerEchoData(SSL* ssl, int clientfd, int echoData, int block,
break;
}
if (err == WOLFSSL_ERROR_ZERO_RETURN) {
free(buffer);
XFREE(buffer, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return WOLFSSL_ERROR_ZERO_RETURN;
}
}
@ -507,7 +507,7 @@ int ServerEchoData(SSL* ssl, int clientfd, int echoData, int block,
}
}
free(buffer);
XFREE(buffer, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (throughput) {
#ifdef __MINGW32__
@ -3635,7 +3635,7 @@ THREAD_RETURN WOLFSSL_THREAD server_test(void* args)
else
printf("Get list of client's protocol name failed\n");
free(list);
(void)wolfSSL_ALPN_FreePeerProtocol(ssl, &list);
}
#endif